edited code:
function archiveRow(){
var from = SpreadsheetApp.openById('###').getSheetByName('archive');
var to = SpreadsheetApp.openById('###').getSheetByName('archive archive');
var values = from.getDataRange().getValues();
var lastRow = from.getLastRow();
var olderthan = new Date().setDate(new Date().getDate() - 9);
for(var row=lastRow;row>1;row--)
{
var timestamp = new Date('A'+row);
if(timestamp.valueOf() < olderthan.valueOf())
{
to.appendRow(values[row]);
from.deleteRow(values[row]);
}
}
}
I'm trying to move some rows from one spreadsheet to another based on the column A 'Timestamp'. So if the Timestamp value is more than 90 days ago from today, then the row should be deleted from spreadsheet 'archive' and appended to spreadsheet 'archive archive'. I'm struggling with the coding. Here's what I have so far.
function testArchive() {
var moveFrom = SpreadsheetApp.openById('###').getSheetByName('archive')
var moveRows = SpreadsheetApp.openById('###').getSheetByName('archive archive')
var col = 1;
var valueToWatch = Date()-90;
var moveFromLastRow = moveFrom.getLastRow();
var moveRowsLastRow = moveRows.getLastRow();
for(var row=moveFromLastRow;row>1;row--){
var values = moveFrom.getRange('A2:Y').getValues();
if (col[row] < valueToWatch){
moveRows.appendRow(values[row]);
}
}
}
I have taken a look at Move Row to Other Sheet Based on Cell Value which does not work for me because I do not want the function to run onEdit.