Home > Blockchain >  Clear cells when checking a checkbox
Clear cells when checking a checkbox

Time:08-11

I had this spreadsheet/script combo working perfectly, then made some visual/organization changes, and now it's not and I'm stumped why.

On the 1st sheet 'Filter' the checkbox in G1 is supposed to clear all of the cells in row 3 (which are my filter conditions).

Any pointers what I'm missing are appreciated!

https://docs.google.com/spreadsheets/d/1syLb6XaAWzmDecMzKWP9TpxZrMprYhLxBqQ4E8hTmmM/edit?usp=sharing

I'm not sure if you're able to view the script or not – here's what I've got currently:

function onEdit(e) {
  if (e.range.columnStart === 7 && e.range.getValue() === TRUE)
    ClearCells();
}

function ClearCells() {
 var sheet = SpreadsheetApp.getActive().getSheetByName('Filter');
 sheet.getRange('A3:F3').clearContent();
}

CodePudding user response:

Replace e.range.getValue() === TRUE by e.range.getValue() === "TRUE" or e.value === "TRUE"

The default options for checkboxes are strings, "TRUE" and "FALSE".

CodePudding user response:

Try this:

function onEdit(e) {
  const sh = e.range.getSheet();
  if (sh.getName() == "Filter" && e.range.columnStart == 7 && e.value == "TRUE")
  sh.getRange("A3:F3").clearContent();
}
  • Related