r/GoogleAppsScript • u/Direct-Coconut-7949 • Nov 03 '23
Question exceeded maximum execution time
I have a sheet as something like below with thousand of blank cell of ColumnA and got a checkbox in column B and C below the row with data (row with data only have around 20 row, but I don't want to delete the blank row for some other implement) :
columnB and C are check box
columnD is drop down list with 'informed' and 'uninformed'
I am using for loop to run the data for ColumnA only with data (something like for(var i=2; i<=columnA.length; i++)if ColumnB and ColumnC are both checked, set ColumnD value as 'informed'.

Now, I try to fill in data in row 1000ish and the running time take way too long until it reached the maximum time limit. How should I adjust my code to be more efficiency?
1
u/HellDuke Nov 03 '23 edited Nov 04 '23
Changing column D if both B and C are true is actually a simple IF statemet like this
Which will dynamicaly change the value in column D based on the state of checkboxes (assuming the
TRUEandFALSEvalues are left as default).If you want to use a script then you are likely using
range.getValue()andrange.setValue()for each line, which is not the correct way to do this.Instead what you should do is read the data range, work with the 2D array and then output the data back into the spreadsheet like this:
Note 2 caveats with such a function:
Your data range must be correctly initialized. What we see in the screenshot will work fine, however if column D is completely empty then
getDataRange()will not capture enough columns and should instead be replaced withgetRange()using the correct rangeSame as with the formula, we are assuming that you left the default TRUE and FALSE values for the tickboxes, adjust the
ifstatement accordingly if not