I am trying to clear the contents of 4 columns of data based on a true/false value of a single cell in another sheet. This is my second script ever. I tried using some examples from these two references: [Google Apps Script to clear multiple ranges] and i need a button to clear multiple ranges in a google spreadsheet.2
I don't think I am calling the value of my trigger cell correctly. I would like the script to run any time the value of this cell is changed.Here is my code:
function clearautocratFields(e) {
/* variables for the function: triggerCell: is contained in the 'Meet Ranges' sheet. It is cell k2. Can be TRUE/FALSE.
dataSheet: is the sheet 'Form Responses 1'. Thats where the cells are that I want to clear.
The Ranges I want to change are 'fg2:fg, fh2:fh, fi2:fi, fj2:fj'*/
var triggerCell = SpreadsheetApp.getActive().getSheetByName('Meet Ranges').getSheetValues('k', '2', 1, 1);
if (triggerCell == 'TRUE'){} else // If the cell is true do nothing
if (triggerCell == 'FALSE'){ // If the cell is false run the script
var dataSheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');// Range to clear
sheet.getRange('fg2:fg').clearcontents();
sheet.getRange('fh2:fh').clearcontents();
sheet.getRange('fi2:fi').clearcontents();
sheet.getRange('fj2:fj').clearcontents();
}
}