Reputation: 109
On Open, In Worksheet "Time per Job & Job Costing", if Row from column A is empty or includes a 0 value hide it. If Column from row 1 is empty or includes a 0
value hide it.
I looked around and can find techniques for hiding rows if a column is empty but not the other way around, nor if the value is 0
.
I have the Rows accomplished with this, but it only works on empty rows:
function onOpen(e) {
["Time per Job & Job Costing"].forEach(function (s) {
var sheet = SpreadsheetApp.getActive()
.getSheetByName(s)
sheet.getRange('A:A')
.getValues()
.forEach(function (r, i) {
if (!r[0]) sheet.hideRows(i + 1)
});
});
}
Upvotes: 1
Views: 286
Reputation: 27348
If Column from row 1 is empty or includes a 0 value hide it.
true
then you hide that particular column.function onOpen() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Time per Job & Job Costing');
const first_row = sh.getRange(1,1,1,sh.getMaxColumns()).getValues().flat();
first_row.forEach((fr,i)=>{
if(fr=='' || fr==0){
sh.hideColumns(i+1);
}});
}
Upvotes: 1