Home > Blockchain >  Google Sheets - When clicking on a checkbox, I want the row to be cleared (not deleted), and also fo
Google Sheets - When clicking on a checkbox, I want the row to be cleared (not deleted), and also fo

Time:06-28

I've been trying to figure this one out and I'm a bit lost...

This is what I have so far:

function deleteCheckedBoxes() {

const sheet = SpreadsheetApp.getActiveSheet();

const activeRange = sheet.getActiveRange();
const activeRow = activeRange.getRow();
const activeColumn = activeRange.getColumn();

let rangeUpdatedValue =  activeRange.getValue();

if(activeColumn == 5 && rangeUpdatedValue == true){

 sheet.deleteRow(activeRow);

};
  
}

How can I get it to clear the row instead of deleting it?

I have tried clearContent & ClearContents, but it doesn't seem to work

Any help would be greatly appreciated!

CodePudding user response:

When your showing script is modified, how about the following modification?

From:

sheet.deleteRow(activeRow);

To:

sheet.getRange(activeRow, 1, 1, sheet.getLastColumn()).clearContent();
  • When this modified script is run, the row of the active range is cleared.
  • In this case, by clearContent(), the checkbox is unchecked.

Reference:

  • Related