I'm trying to make a Google Apps Script that applies a filter function to each sheet in my spreadsheet except for certain sheets. I'd like it to ignore particular named sheets, as well as a "blankSheet" variable. I'd like "blankSheet" to consist of any sheets that have no data in a particular range of cells (A2:H).
I tried the following, but the resulting filter function in my spreadsheet still includes an empty sheet. Thanks for the help!
function myFunction() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const shts = ss.getSheets().filter(sh => sh.getDataRange().isBlank()).map(s => s.getName()).join(',');
//set variables
const masterSheet = "master";
const masterSheetFormulaCell = "A2";
const ignoreSheets = ["notifications","main",shts];
const dataRange = "A2:I";
const checkRangeA = "A2:A";
const checkRangeB = "B2:B";
const checkRangeC = "C2:C";
const checkRangeD = "D2:D";
const checkRangeE = "E2:E";
const checkRangeF = "F2:F";
const checkRangeG = "G2:G";
const checkRangeH = "H2:H";
const checkRangeI = "I2:I";
//end set variables
ignoreSheets.push(masterSheet);
const allSheets = ss.getSheets();
const filteredListOfSheets = allSheets.filter(s => ignoreSheets.indexOf(s.getSheetName()) == -1);
let formulaArray = filteredListOfSheets.map(s => `FILTER({'${s.getSheetName()}'!${dataRange},"${s.getSheetName()}" &LEFT(ROW('${s.getSheetName()}'!${checkRangeA}),0),ROW('${s.getSheetName()}'!${checkRangeA})},'${s.getSheetName()}'!${checkRangeB}&'${s.getSheetName()}'!${checkRangeC}&'${s.getSheetName()}'!${checkRangeD}&'${s.getSheetName()}'!${checkRangeE}&'${s.getSheetName()}'!${checkRangeF}&'${s.getSheetName()}'!${checkRangeG}&'${s.getSheetName()}'!${checkRangeH}&'${s.getSheetName()}'!${checkRangeI}<>"")`);
let formulaText = "=SORT({" + formulaArray.join(";") + "},10,True,11,True)";
ss.getSheetByName(masterSheet).getRange(masterSheetFormulaCell).setFormula(formulaText);
}