1

When I have multiple sheets in a spreadsheet, I want to execute a trigger only when One of the Sheets is changed, not the others. OnChange() or OnEdit() is executing the trigger for any data change.

Any suggestions?

  • 1
    Use an if statement – Rubén Jul 7 '18 at 17:58
0

We can't limit a trigger to be executed only on certain sheets but we could limit if some parts of the code are executed if a condition is met. For this, we could use JavaScript statements like if, switch, etc.

Simple edit trigger example:

function onEdit(event){
  var sheet = event.range.getSheet();
  if(sheet.getName() === 'Sheet1') {
    //do something
  }
}

Notes:

Some operations doesn't return the active range/sheet, when using a change trigger. Ref. getActiveRange() incorrect in onChange trigger for some column/row operations

Related Q&A

0

you can specify on which sheet will be script executed (as Rubén's example):

function onEdit(event){
  var sheet = event.range.getSheet();
  if(sheet.getName() === 'Sheet1') {
    //your script
  }
}

or for example only on the active sheet like:

function onEdit(event){ 
  var sheet = event.source.getActiveSheet();
  //your script
}
  • It's not clear how this answer the question, I think. – Rubén Jul 8 '18 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.