I have a Google spreadsheet where column A has checkboxes in each row. I have written a script to perform a function on all rows where the checkboxes are checked, but I want to add in at the end a reset function so that all checked boxes are unchecked again after the script is run.
I've tried using a for loop like this:
var dataRange = sheet.getRange('A3:A');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] == true) {
values[i].setValue(false);
}
}
}
But clearly this doesn't work as I get an error.
Does anyone know how this could be done?
Alternatively, Since you want to uncheck everything in the range (and all of the range have checkboxes in them), just do:
without checking/looping.
This solution posted above does reset all checkboxes; however, it also unexpectedly changes cells with the value of 1 in it to FALSE.
I want to make a script to reset checkboxes on ALL sheets...
How about this modification? I think that there are several solutions for your situation. So please think of this as one of them.
Modification points :
values[i].setValue(false);
.values[i]
is an array. Please use the range forsetValue()
.setValue()
in the for loop leads to higher cost. So in this modification, I usedsetValues()
.values
, ifvalues[i][j]
is "true".setValues()
.Modified script :
Reference :
If this was not what you want, please tell me. I would like to modify it.