The script I am using loops through a spreadsheet and deletes items in rows where there is a checkmark.
I need it to have a variation on certain rows. In this example, I also need it to delete contents in column A for rows 123-137 if the checkbox in F is checked.
This script is amazing script, and was helped tremendously by Tanaike
If Checkbox is checked, use a script to clear specified cells in row and clear checkbox after script is run
I've tried changing the script below to include:
return ar.concat(["B" + (i + 1) + ":D" + (i + 1), "F" + (i + 1), "A123:A137"]);
And lots of other tweaks. I don't fully understand what is going on in this script.
function deleteRowContents (col){ // col is the index of the column to check for checkbox being true
var col = 6; // If the column "F" is 6, please set 6.
var sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet4"); // Modified
var data = sh.getDataRange().getValues();
// Below script was modified.
var deleteRanges = data.reduce(function(ar, e, i) {
if (e[col - 1] === true) { // Modified
return ar.concat(["B" + (i + 1) + ":D" + (i + 1), "F" + (i + 1)]);
}
return ar;
}, []);
if (deleteRanges.length > 0) { // or if (deleteRanges.length) { // Added
sh.getRangeList(deleteRanges).clearContent();
}
}
EXPECTED RESULTS: For specified rows 123-137, also clearContent from Column A if checkbox in F is checked.
Actual results: Script errors, adding exponential number of rows, etc.