Your answer lies in capturing the edit event when the user modifies any cell on the sheet. The user can modify any cell, of course. Your job is to determine if that cell is in the range you care about. The onEdit
event can be captured using this function:
function onEdit(eventObj) {
//--- check if the edited cell is in range, then call your function
// with the appropriate parameters
}
The object passed into the event describes the cell that was edited. So we set up a "check range" and then make a comparison of that range to whichever cell was edited. Here's the function:
function isInRange(checkRange, targetCell) {
//--- check the target cell's row and column against the given
// checkrange area and return True if the target cell is
// inside that range
var targetRow = targetCell.getRow();
if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;
var targetColumn = targetCell.getColumn();
if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;
//--- the target cell is in the range!
return true;
}
The full event function for the edit event would be
function onEdit(eventObj) {
//--- you could set up a dynamic named range for this area to make it easier
var checkRange = SpreadsheetApp.getActiveSheet().getRange("B2:B10");
if (isInRange(checkRange, eventObj.range)) {
//--- the ID cell is on the same row, one cell to the left
var idCell = eventObj.range.offset(0,-1);
//--- the status cell is the one that was edited
var statusCell = eventObj.range;
updateProjectStage(statusCell, idCell);
}
}
Here's the whole thing all together:
function isInRange(checkRange, targetCell) {
Logger.log('checking isInRange');
//--- check the target cell's row and column against the given
// checkrange area and return True if the target cell is
// inside that range
var targetRow = targetCell.getRow();
if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;
Logger.log('not outside the rows');
var targetColumn = targetCell.getColumn();
if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;
Logger.log('not outside the columns');
//--- the target cell is in the range!
return true;
}
function onEdit(eventObj) {
//--- you could set up a dynamic named range for this area to make it easier
var checkRange = SpreadsheetApp.getActiveSheet().getRange("B2:B10");
if (isInRange(checkRange, eventObj.range)) {
Logger.log('cell is in range');
//--- the ID cell is on the same row, one cell to the left
var idCell = eventObj.range.offset(0,-1);
//--- the status cell is the one that was edited
var statusCell = eventObj.range;
updateProjectStage(statusCell, idCell);
} else {
Logger.log('must be outside the range');
}
}
function updateProjectStage(status, id) {
Logger.log('we are updating');
}