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?
Select All Checkboxes With Spacebar Highlight a range of checkboxes. Press the spacebar to toggle them checked or unchecked.
To delete all checkboxes at a time, go to the Home tab > Editing group > Find & Select > Go To Special, select the Objects radio button, and click OK. This will select all the check boxes on the active sheet, and you simply press the Delete key to remove them. Note.
If you want to remove multiple check boxes, highlight all of the lines you want to change. Click on the arrow on the right side of the “Bullets” button. From the next window, select the “None” option in the “Bullet Library” section.
Pressing the Ctrl key, you can click, or click-and-drag to deselect any cells or ranges within a selection. If you need to reselect any of those cells, continue holding the Ctrl key and reselect those cells (for Mac, use the Cmd key).
How about this modification? I think that there are several solutions for your situation. So please think of this as one of them.
values[i].setValue(false);
. values[i]
is an array. Please use the range for setValue()
.
setValue()
in the for loop leads to higher cost. So in this modification, I used setValues()
.values
, if values[i][j]
is "true".setValues()
.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
If this was not what you want, please tell me. I would like to modify it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With