-2

I'm not at all too familiar with creating script to run in Google sheets.

But I'm looking to be able to hide any given row once the input date has passed today's date. I've attached the sheet.

Spreadsheet

Would anyone be able to help me?

BigBen
  • 46,229
  • 7
  • 24
  • 40

1 Answers1

0

Try this:

function hideOldRows(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var rg=sh.getDataRange();
  var vA=rg.getValues();
  var dt=new Date();
  var tdv=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
  for(var i=1;i<vA.length;i++) {
    if(new Date(vA[i][2]).valueOf()<tdv){
      sh.hideRows(i+1);
    }
  }
}

If used with a trigger:

function hideOldRows(e){
  var rg=e.range;
  var sh=rg.getSheet();
  var inclA=['Patrick'];//You can add other sheet names to the included list of sheets. The function will return for other sheets on the next line.
  if(inclA.indexOf(sh.getName())==-1){return;}
  var rg=sh.getDataRange();
  var vA=rg.getValues();
  var dt=new Date();
  var tdv=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
  for(var i=1;i<vA.length;i++) {
    if(new Date(vA[i][2]).valueOf()<tdv){
      sh.hideRows(i+1);
    }
  }
}

You can't run this function from script editor because onEdit trigger provides an event object represented by the letter e in this function which is needed for this function. Please read this reference

Cooper
  • 59,616
  • 6
  • 23
  • 54