0
votes

My script works great but only for the active sheet. How can it be changed so it searches the entire workbook and checks same cell location (example: 'AC2') in each sheet for a value of 1 or 2 and chooses whether to hide or show that sheet, and then check the others and do the same?

I've tried for days trying to find an example, but the only ones I've found are referenced to a cell in a unique spreadsheet that controls the actions for all the others and I haven't much experience with google scripts to make it check each spreadsheet at the same time. There will be about 46 sheets by the time it's finished.

I've got the triggers sorted.

Thanks so much for any help you can provide

` function yesterday2() { var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets();

  if(ss.getRange('AC2') == 1) {
    ss.hideSheet();
  }

  if(ss.getRange('AC2') == 2) {
    ss.showSheet();
   }
}

`

1
Welcome to Stack Exchange. Here are a couple of examples of how you might iterate each sheet, with a twist: webapps.stackexchange.com/questions/114391/…Dennis

1 Answers

1
votes
function yesterday2() {
  const ss = SpreadsheetApp.getActive()
  const shts=ss.getSheets();
  shts.forEach((s,i)=>{if(s.getRange('AC1').getValue()==1){s.hideSheet();}else{s.showSheet();}}); 
}