Search code examples
google-apps-scriptgoogle-sheetshide

Google Spreadsheet Hide and unhide rows based on cell values


I have a spreadsheet with date's (Months) I'm looking for a script that hides and unhide's rows automatically.

In column "Z" is a formula (=IF(A3=TODAY();"";"1")) So the cells containing "1" has to hide the row and the empty cells should unhide the row.

Can anyone help me? I have seen a lot of forums with no result for me :(

See the example below!

Example


Solution

  • function hideShow() {
      var ss=SpreadsheetApp.getActive();
      var sh=ss.getActiveSheet();
      var rg=sh.getRange(3,26,sh.getLastRow()-2,1);
      var vA=rg.getValues();
      for(var i=0;i<vA.length;i++) {
        if(vA[i][0]==1) {
          sh.hideRows(i+3);
        }
        if(vA[i][0]==0) {
          sh.showRows(i+3);
        }
      }
    }