Reputation: 2509
I have a column of checkboxes which the user can set to true or false - I want to run a Google Apps Script on the click of a button which resets the value of all the checkboxes to False.
I found a related question, and attempted to implement the solution from the accepted answer. Unfortunately, it doesn't seem to work as intended, and I don't know enough about Apps Script to understand why. Here is my code (barely modified from Tanaike's solution):
function resetBoard() {
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange('L5:L');
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;
}
}
}
dataRange.setValues(values);
}
Here is the sheet - the checkboxes in Column L are the ones I'm trying to reset. After I press the button to execute the script, it says that the script is finished, but nothing has changed:
Is there a simple mistake that explains why this isn't working?
Upvotes: 1
Views: 1407
Reputation: 201428
Here is my understanding:
false
.values[i][j] == false;
is required to be modified. In this case, values[i][j]
is compared with false
. So when you use this script, please modify to values[i][j] = false;
.resetBoard()
is run, how about unchecking all checkboxes of "L5:L"?function resetBoard() {
SpreadsheetApp.getActiveSheet().getRange('L5:L').uncheck();
}
Upvotes: 2