I am using the below code to hide and unhide rows which I got from the below question posted in Stakeoverflow community.
Hide Blank Rows In Google Sheets Based On Selection
The code runs when I change the selection in "NamedRange1" i.e. Cell No. A1 of Sheet3. If I select A in this section then blank rows in Sheet2 will get hide and if I select B then the rows will get unhide.
The code runs fine and hides unhides the rows but I am getting issue in below case:
I selected A in NamedRange1 so blank rows in Sheet2 will get hide, then I manually hide one row (Say row No.7) in Sheet2 which is having data and now if I select B in NamedRange1 then the script will unhide hidden rows except Row No. 7. I want to update the script so it can unhide all the hidden rows.
For reference am sharing the link of the sheet which is having the sample data as well as the code.
function onEdit(e) {
const sh = e.range.getSheet();
const rg = e.source.getRangeByName("NamedRange1");
const sr = rg.getRow();
const sc = rg.getColumn();
const er = sr + rg.getHeight() - 1;
const ec = sc + rg.getWidth() - 1;
if (sh.getName() == "Sheet3" && e.range.columnStart >= sc &&
e.range.columnStart <= ec && e.range.rowStart >= sr &&
e.range.rowStart <= er && e.value) {
//e.source.toast("Flag1")
const sh2 = e.source.getSheetByName("Sheet2");
const vs = sh2.getDataRange().getValues();
vs.forEach((r, i) => {
if (r.every(e => e == '')) {
if (e.value == "A") {
sh2.hideRows(i + 1);
} else {
sh2.showRows(i + 1)
}
}
});
}
}
Any help on above will be appreciated.