I'm working now on hiding a row if a certain cell is empty. The code for hiding a rows works, but I encountered a problem with it. Here's a sample spreadsheet that I'm trying to do: LINK
As you can see, it will work if column A didn't have any value on it.
But when I put something in column A, it will look like this.
Here's the code for hiding the rows:
var startRow = 6;
var colToCheck = 2;
function script_HideRows() {
var sheetNames = ["MS_Q1", "MS_Q2", "MS_Q3", "MS_Q4", "SUMMARY"]; // Please set the sheet names here. In this case, 4 sheets are used.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.getSheets().forEach(sheet => {
var sheetName = sheet.getSheetName();
if (sheetNames.includes(sheetName)) {
if (sheetName == "SUMMARY") { // When the sheet is "SUMMARY", the start row is changed.
startRow = 7;
}
var numRows = sheet.getLastRow();
var elements = sheet.getRange(startRow, colToCheck, numRows).getValues();
for (var i=0; i<(numRows - startRow); i++) {
if (shouldHideRow(sheet, i, elements[i][0])) {
sheet.hideRows(startRow + i);
}
}
// Hide the rest of the rows
var totalNumRows = sheet.getMaxRows();
if (totalNumRows > numRows)
sheet.hideRows(numRows+1, totalNumRows - numRows);
}
});
}
I got that code from here: LINK
I just want to hide all the rows that have an empty cell within the column B.
I hope someone can help me. Sorry for the poor English. Thank you in advance!
var colToCheck = 2
which means column B, the code works fine. 3) Having said all that, what is the error you are encountering? Provide a minimal reproducible example. – soMario