I have designed below script from solution given in one of the question posted from the Stakeoverflow community (Show and hide rows and columns based on different dropdowns).
In the solution given in the above link, specific rows/columns are being hide by using the script, I want to hide all the blank rows in place of specific rows.
Script which I am using
function onEdit(e) {
const n1=e.source.getRangeByName('Sheet3!NamedRange1').getValue();
const sh2=e.source.getSheetByName("Sheet2");
if (n1=="A"){sh2.showRows(15,10);}else{sh2.hideRows(15,10);}
}
Any help on above will be greatly appreciated.
CodePudding user response:
Hide and Show Row based on value in NamedRang1
function onEdit(e) {
//e.source.toast("Entry")
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)
}
}
});
}
}