function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Label Selection"); //change this to the name of your sheet
ui = SpreadsheetApp.getUi();
//PICK ONE & comment out the other one:
//var names = ss.getRange("B2:E");//Use this if you are naming the range
var names = ss.getRange("A2:A");//Use this if you are naming the ranges
var namesValues = names.getValues(); //Get array of all the names
//PICK ONE & comment out the other one:
//var checkboxes = ss.getRange("B2:E"); //Use this if you are naming the range
var checkboxes = ss.getRange ('B2:B'); //Use this if you want to hard-code your range
var cbRows = checkboxes.getHeight(); //Get # of rows in the ranges
var cbValues = checkboxes.getValues(); //Get array of all the checkbox column cell values
//Logger.log(cbValues);
var newCBValues = new Array(cbRows); //Create an array to store all the new checkboxes values before we edit the actual spreadsheet
for (var row = 0; row < cbRows; row++) {
newCBValues[row] = new Array(0); // Make the array 2 dimensional (even though it only has 1 column, it must be 2D).
if (namesValues[row] == "" || namesValues[row] == " ") { //If the name cell of this row is empty or blank then...
newCBValues[row][0] = " "; //Set the value to one space (which will make the cell NOT true or false, and thus NOT display a checkbox).
//Logger.log("newCBValues[" + row + "][0]: " + newCBValues[row][0]);
}else{ //otherwise, if the name cell isn't blank...
if (cbValues[row][0] === true) {
newCBValues[row][0] = true; //Keep the checkbox checked if it's already checked
}else{ //If the name cell isn't blank, and it's not true...
newCBValues[row][0] = false; //Then Keep it or set it to False (an empty checkbox):
}
}
}
checkboxes.setValues(newCBValues); // now that we have a completed array of our new checkbox values, let's edit the sheet with them!
}
When i put text in A2 it put a checkbox in B2 which is great but i also want it to put a checkbox in C2, D2 & E2 but when i change the ss.getRange ('B2:B') to ('B2:E') it gives me this error