I'm trying to get a checkbox to run a script on the row it is in. It needs to loop through all rows in the specified sheet.
If a checkbox is checked in Column F, I want to schedule a script to clear columns B-F.
B is a checkbox that should be set to FALSE C is a data validated input D is data validated input E is a formula that relies on data in C and D. The formula should remain.
F being true is the triggering checkbox
If F is checked, then clear contents in B,C,D, F (E shouldnt be cleared since it's a formula)
I've tried modifying scripts from here and other links without success:
Reset checkboxes to false
Using a script to generate docs from rows in Google Sheet if checkbox is checked
Google Sheets Script to Hide Row if Checkbox Checked
function try_It(){
deleteRow(5); //// choose col = 2 for column C, 5 for F
}
function deleteRowContents (col){ // col is the index of the column to check for checkbox being true
var sh = SpreadsheetApp.getActiveSheet();
var data = sh.getDataRange().getValues();
var targetData = new Array();
for(n=0;n<data.length;++n){
if(data[n][col]!="TRUE" && data[n][col]!="FALSE"){ targetData.push(data[n])};
}
Logger.log(targetData);
sh.getDataRange().clear();
sh.getRange(1,1,targetData.length,targetData[0].length).setValues(targetData);
}
Expected results: If Column F is checked, clear B:F in same rows.(I know this script above is not even close to being complete).
Actual results: This deletes all the formatting on the entire sheet. It doesn't clear range properly even in the column F checkbox.