Reputation: 123
I've been wondering if there was a way to select a cell in a particular column, when the other particular column has been edited, using Google Apps Script?
For example: **If someone edits B3, my script should select C3 (if someone edits B23, then C23), but someone edits let's say A5- then nothing happens.**
See the example picture below
Thank you in advance!
Upvotes: 1
Views: 678
Reputation: 64100
function onEdit(e) {
const sh = e.range.getSheet();
if (sh.getName() == `YOUR SHEET NAME` && e.range.columnStart == 2 ) {
e.range.offset(0,1).activate();
}
}
Upvotes: 1
Reputation: 1630
It's possible through the onEdit
trigger, data from the e
/event object
, and .activate()
.
function onEdit(e) {
if (e.source.getActiveSheet().getName() === `Sheet1`) {
if (e.range.rowStart === 5 && e.range.columnStart === 1) return
e.source.getActiveSheet()
.getRange(e.range.rowStart, e.range.columnStart+1)
.activate()
}
}
function onEdit(e) {
// If the sheet ('Sheet1') was edited..
if (e.source.getActiveSheet().getName() === `Sheet1`) {
// "Cancel" if A5 was selected.
if (e.range.rowStart === 5 && e.range.columnStart === 1) return
// Get the active sheet
e.source.getActiveSheet()
// Select the range of "edited row", "edited column +1"
.getRange(e.range.rowStart, e.range.columnStart+1)
// "Select" the cell.
.activate()
}
}
If you would like to 'ignore' more than A5, please let me know and I can update the examples for you.
Learn More:
Upvotes: 2