Reset checkboxes to false
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 :
- The reason of the issue is
values[i].setValue(false);
.values[i]
is an array. Please use the range forsetValue()
.- But to use
setValue()
in the for loop leads to higher cost. So in this modification, I usedsetValues()
.
- But to use
- Put "false" to
values
, ifvalues[i][j]
is "true". - Put the modified values to the sheet using
setValues()
.
Modified script :
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][j] = false; // Modified
}
}
}
dataRange.setValues(values); // Added
Reference :
- setValue()
- setValues()
If this was not what you want, please tell me. I would like to modify it.
Update:
You can now use range.uncheck()
directly on the range
Alternatively, Since you want to uncheck everything in the range (and all of the range have checkboxes in them), just do:
sheet.getRange('A3:A').setValue(false);
without checking/looping.