Skip to content
Advertisement

Apps Script: How to limit the scope of a FOR LOOP?

The script below runs whenever any cell in column E (so, array [4]) has been edited. And its only purpose is to add some additional information to the subsequent empty cells of the row that has been edited. But instead of just adding these information to the next cells that are empty in the same row, my script is re-setting the values of all subsequent cells, even if these subsequent cells already have each some values in them. Can somebody please tell me what I am doing wrong here and how to fix it? It´s obvious that I am doing something wrong in my IF-statement, but I honestly have no idea what that could be 🙁

Thank you so much in advance for your help and hints!!!


Here is the script:

JavaScript

And here is the trigger:

JavaScript

Advertisement

Answer

Adding data to just line that you are on will limit the scope

Trying to loop through the entire sheet is a bad idea since this script will max out after 30 seconds.

In my testing I used a validation in column 5 using the list COMPLETED,APPROVAL

JavaScript

Sheet0:

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement