Reputation: 321
I currently have the following script but in contrast to my expectations it only hides the rows with non-empty cells in column F and keeps the one with empty cells unhidden...what is wrong? ==="" is correct right?
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange(6,6,274,1);
function onOpen() {
{
//get the values to those rows
var values = range.getValues();
//go through every row
for (var i=0; i<values.length; i++){
//if row value is equal to empty
if(values[i][0] === ""){
//hide that row
sheet.hideRows(i+1);
}
}
}
Also, is there a way to do this whole thing in multiple sheets but with different ranges without having to completely multiplying the whole script with different variables? I am quite new to AppScript and the "for every i" is still something I do not understand how it works...Thank you so much for your help!
Edit: Can I also add another
if(values[i][0] > "") { sheet.showRows(i+1)};
to check for changes in the rows and unhide them again?
Upvotes: 0
Views: 840
Reputation: 64032
function onOpen() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getActiveSheet();
const vs = sh.getRange(6, 6, 274, 1).getValues().flat();
vs.forEach((e,i) => {if(!e)sh.hideRows(i + 6);});
}
Upvotes: 1