Wesley
Wesley

Reputation: 3

Hide Individual Google Sheets by Cell Value in each sheet

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();
   }
}

`

Upvotes: 0

Views: 173

Answers (1)

Cooper
Cooper

Reputation: 64062

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();}}); 
}

Upvotes: 1

Related Questions