I have a column with a checkbox in the final column that operates off of a standard if/then formula. The checkbox will check itself if all other cells (also checkboxes) in the same row are either checked or blank.
I am trying to hide the relevant row when the checkbox is checked. I would like this to trigger as soon as the checkbox is updated by its formula.
This is what I have so far, but I've been trying to change this for hours as well as scrawling other answers and haven't had any luck.
function onEdit(eventObj) {
var thisSheet = SpreadsheetApp.getActiveSheet();
var checkbox = eventObj.range;
var rowIndex = checkbox.getRow();
var boxA1 = checkbox.getA1Notation();
var boxColumn = 'P' boxA1.substring(1);
var boxRange = SpreadsheetApp.getActiveSheet().getRange(boxColumn);
var boxVal = boxRange.getValue();
if (checkbox.getValue() == true && boxVal== true) {
Logger.log('hiding the row');
thisSheet.hideRows(rowIndex, 1);
} else {
Logger.log('showing the row');
thisSheet.showRows(rowIndex, 1);
}
}
I also attempted to use thisSheet.getRange(rowIndex,checkbox.getLastColumn()) to attempt to target the final column, but this didn't work either. The end result, even when both the updated cell and the final column cell are checked, is to fail the if statement in the code and not hide the row.
CodePudding user response:
Found an answer via https://webapps.stackexchange.com/questions/69129/batch-hiding-function-in-google-script/153235#153235. Provides 2 answers for individual row hiding and batch hiding.