Forum Discussion
Auto HIDE ROWS based on 2 cells
To do this you need either VBA (macro) or use scripting. Since VBA isn't supported in online Excel but scripting is supported in both I recommend scripting. Here is a script I created to filter/unfilter (i.e. I have a single button to toggle between filtered or not filtered)
/**
* This script filters table.
*/
function main(workbook: ExcelScript.Workbook) {
//Unlock worksheet
let wksht = workbook.getActiveWorksheet()
wksht.getProtection().unprotect()
//Get table
let tbl = workbook.getTable("Table1")
// Sort the table based on the column.
if ( tbl.getAutoFilter().getIsDataFiltered() ) {
tbl.clearFilters()
} else {
tbl.getColumn(6).getFilter().applyValuesFilter([""]);
}
wksht.getProtection().protect()
}
This will unprotect the sheet (no password), either clear any filters or apply filter to show only "" on column 6, and then re-protect the sheet (no password).
You do need a business or school account to use scripting and it will need a button press (but that is no different than your drop down option and doesn't require a macro always checking on any change on the whole sheet). I would imagine you might want the button named something like "Toggle Show Active/All" and change the code to column 2 and "A" instead of "". And don't forget to change the table name from "Table1" if needed.