A script to move rows from one sheet to another based on certain conditions. I run this trigger every 24 hours to get rid of past data and save it as a backup so my apps are always easier and quicker to load.
function moveRows() {
var ss = SpreadsheetApp.getActive();
var source = ss.getSheetByName('Sheet1');
var val = source.getDataRange().getValues();
var PDate = new Date(new Date().setHours(0,0,0,0))
for (var row = val.length - 1; row >= 0; --row) {
Logger.log("Check: "+ val[row][1]+'----'+ PDate)
if ((val[row][42] == 'Completed' || val[row][42] == 'Cancelled') && val[row][1] <= PDate && val[row][39] == 3) {
ss.getSheetByName('Closed')
.appendRow(val[row]);
source.deleteRow(parseInt(row) + 1);
}
}
}