There is an Event , provided as a parameter of your onEdit()
function, and contains the necessary information about what has been edited. If you are interested in what this (e)
, here it is.
Since the onEdit()
function is called for each edit, you should invest as little processing as possible when deciding whether to exit. Using the event that has passed, you will need fewer service calls, so it will be more efficient. The way Rasmus answer converts A1 notation to column and row numbers is good if you need to be flexible, but if the editing range is fixed, you can simply use constant values ββfor comparisons - again, to reduce the processing time required.
function onEdit(e) { var editRange = { // B4:J6 top : 4, bottom : 6, left : 2, right : 10 }; // Exit if we're out of range var thisRow = e.range.getRow(); if (thisRow < editRange.top || thisRow > editRange.bottom) return; var thisCol = e.range.getColumn(); if (thisCol < editRange.left || thisCol > editRange.right) return; // We're in range; timestamp the edit var ss = e.range.getSheet(); ss.getRange(thisRow,7) // "G" is column 7 .setValue(new Date()); // Set time of edit in "G" } β
source share