简体   繁体   中英

Google Script to Move Range of cells to Archive sheet on time sensitive trigger

I am relatively new to Google App Scripting and I have a conundrum right now. I am trying to have a range cells if they have data in them to move to archive sheet.

Basic premise: I have a schedule for trucking that is a week at a time. I share this with multiple other people and I do not want to make a new sheet each week. I currently have tabs for each day of the week.

I am needing for the rows with data in them to move to the Archive Sheet after the respective day (Monday, Tuesday, etc...) has finished. This will leave the sheet with that day blank.

Try this:

function archiveYesterday() {//run on a timebased trigger after midnight
  var ss=SpreadsheetApp.openById('SpreadsheetId');
  var ash=ss.getSheetByName('archivesheet')
  var sheetsA=['','Monday','Tuesday','Wednesday','Thursday','Friday',''];
  var rangeA=['','A2:G9','A2:G9','A2:G9','A2:G9','A2:G9','A2:G9',''];//Daily Ranges if they change
  var dayidx=new Date().getDay()-1;
  if(dayidx>0 && dayidx<6) {
    var sh=ss.getSheetByName(sheetsA[dayidx]);
    if(sh) {
      var rg=sh.getRange(rangeA[dayidx]);
      var vA=rg.getValues();
      for(var i=0;i<vA.length;i++) {
        ash.appendRow(vA[i]);
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM