So I have a file on Sheets, and in the file is a section of cells that are formatted so when you enter "0", they are empty circles, and when you enter any other number (I just go with "1" to make it easy), the circles are filled. I know I could probably use the formulas in the actual sheet, but I'd like the option to edit the cells individually. I really only need the dropdown to fill them all at once or clear them all to save time. And the dropdown has options "Clear" and "Fill".
I have the dropdown menu in grouped cells AG97:AN97 and I'd like to be able to change the cells in W100:W103 (there are more ranges, but one step at a time.)
I've tried using previous questions to help me, but I can't seem to grasp the code.
function addValidation() {
var range = SpreadsheetApp.openById('(SHEETID)');
var sheet = ss.getSheets()[0];
var values = range.getValues();
var data = sheet.getDataRange().getValues();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(["Clear", "Fill"]).build();
for(var i=0; i<data.length; i++) {
if(data[i][22] == "Clear") {
sheet.getRange(i+100, 7).clear().setDataValidation(rule);
}
}
}
I replaced the sheet idea just for the purpose of showing code. I tried to get the clear function to work before I tried working on fill, but no luck. I keep getting "Bad value (line 2, file "Code")"
If your Spreadsheet URl is something like
https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/edit#gid=0, then the ID is the part designated with X - usualy 44 characters long.
Yuo need to pass it to the method openById() in quotes (or double quotes), but without brackets:
SpreadsheetApp.openById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
Also, probably you want to assign it to a variable called ss rather than range, given your next line is var sheet = ss.getSheets()[0];.
var values = range.getValues();- Isabella LeonardReferenceError: "range" is not defined. (line 4, file "Code")- Isabella Leonardvar ss = SpreadsheetApp.openById('(SHEETID)'); var sheet = ss.getSheets()[0]; var range = sheet.getRange("W100:W103");- ziganotschkafunction onEdit(e) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var cell = sheet.getRange("AG97"); var cellContent = cell.getValue();var lvlone = SpreadsheetApp.getActiveSpreadsheet().getRange("W100:W103");if(cellContent === "Fill"){ lvlone.setValues([ ["1"], ["1"], ["1"], ["1"] ]);}- Isabella Leonardlvlone.setValues([ [1], [1], [1], [1] ]);instead given that integers opposed to strings do not need to go in quotes. - ziganotschka