I'm attempting to transition a macro into an OnEdit function.
My range is A2:R7. It has no visible filter. There are checkboxes in Col A (A3:A7).
If a checkbox is checked, I want it to clear the corresponding contents of the active row (A:O) and (Q:R). Note, Col P has a formula in it, which I wish to maintain.
When the contents have been cleared, I want it to uncheck the box, and sort the remaining contents in the range (A2:A7).
He is the Macro assigned to Row 5.
function macro1() {
var spreadsheet = SpreadsheetApp.getActive();
// Set checkbox to FALSE
spreadsheet.getRange('A5').activate();
spreadsheet.getCurrentCell().setValue('FALSE');
// Clear contents Col B to Col O and Col Q to Col R
spreadsheet.getRange('B5:O5').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
spreadsheet.getRange('Q5:R5').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
// Create filter, sort, remove filter
spreadsheet.getRange('A2:R7').createFilter();
spreadsheet.getActiveSheet().getFilter().sort(2, true);
spreadsheet.getActiveSheet().getFilter().remove();}
My attempts at solving it have been relatively futile, as I'm very new to using scripts. The primary point of frustration is around assigning it to a checkbox.