简体   繁体   中英

In google sheets - how do I apply an onEdit trigger to run on just one cell on one sheet?

Thanks in advance for your help...

I need to run a script upon editing just a single cell in a specific sheet.

A new row is first appended to the bottom of the dataRange.

The user first selects a date from a datePicker in Col A and then selects an entry from a list (using Data Validation) in Col B.

The idea is to use the textFinder to find the first previous row that matches the selected list item in Col B so that other cells on the new row can be populated from the found matched row.

All is working well except for the trigger.

Any ideas on how to trigger the script would be gratefully received!

Question regarding trigger... Could the trigger cell have a check box...the script would check if “true”...then run function and clear checkbox.

I believe onChange is global for the entire sheet. However, you could do time based that would check true or false.

Answer:

You can use an onEdit(e) trigger containing a conditional which only executes if a certain cell has been edited.

Code:

You can run whatever script you like on the edit of a specific cell by first checking the range of the edit using the event object:

function onEdit(e) {
  if (e.range == 'A1') {
    // put the code you want to run here
  }
  // you can put additional else if statements here if you want other code to
  // execute on other cells being edited
  else {
    return;
  }
}

Make sure to run the script manually one time first so that you can authenticate!

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM