1
votes

I would like to restrict an onEdit function to a specific cell (A1) in a specific sheet (Sheet1). So the code will only run when I make an edit in A1/Sheet1. My code below works for A1, but in all sheets.

function onEdit(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var range = e.range
    Logger.log(range.getA1Notation())

    if(range.getA1Notation() == "A1"){}
1

1 Answers

1
votes

How about this modification?

Modification points :

  • Retrieve the sheet name and the range using e of onEdit(e).
  • When sheetName and range are "Sheet1" and "A1", respectively, the script of // do something is run.

Modified script :

function onEdit(e) {
  var sheetName = e.source.getActiveSheet().getSheetName();
  var range = e.range.getA1Notation();
  if (sheetName == "Sheet1" && range == "A1") {
    // do something
  }
}

If I misunderstand your question, please tell me. I would like to modify it.