So I'm looking to auto-hide completely empty rows. With the code, I have now it is autohiding everything with an empty A column when I would still like the columns and rows with N/A shown, reference screenshot#1. I would also like for it to update onOpen or onChange and "unhide" previously empty rows that now have values. By this, I mean this spreadsheet is based on a query & importrange from another spreadsheet that only pulls over certain columns. So the other sheet is the sheet that gets edited, and this one updates with importrange. Hence, if something is added to a previously empty row (for the purpose of this spreadsheet, an assignment to an individual), I would like it to unhide the rows that now contain data as well.
Additionally, this only seems to work when I'm logged in with the ability to "edit" not when view-only and accessible by the public.
Screenshot#1 (All Rows showing)
Screenshot#2 ("Blank" rows hiding)
Screenshot#3 (View-only mode does not update with script)
This is to clean up formatting by hiding empty rows. I've gotten the progress I have by searching solutions, and have come to a dead end.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn());
function onOpen() {
var menuEntries = [];
menuEntries.push({name: "Show All Rows", functionName: "showAllRows"});
menuEntries.push(null);
menuEntries.push({name: "Hide Empty Rows", functionName: "hideEmptyRows"});
ss.addMenu("Row Visibility", menuEntries);
}{
//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);
}
}
}
function showAllRows(){
sheet.showRows(1,sheet.getLastRow());
}
function hideEmptyRows(){
//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);
}
}
}