Setting up so any expired date rows get deleted. But I would Like to Delete and Move to Archive
tab (sheet).
Have tried taking other codes and integrating but cannot find the code.
function DeleteOldEntries() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Current'); // assumes Current is the name of the sheet
var datarange = sheet.getDataRange();
var lastrow = datarange.getLastRow();
var values = datarange.getValues(); // get all data in a 2D array
var currentDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000); // tomorrow
for (var i = lastrow; i >= 2; i--) {
var tempDate = values[i - 1][1]; // arrays are 0 indexed so row1 = values[0] and col3 = [2]
if (tempDate != NaN && tempDate <= currentDate) {
sheet.deleteRow(i);
} // closes if
} // closes for loop
} // closes function
Best Answer
Try this
In other ways you can adopt the next snippet. This removes all rows which contains 'asdf' in B-column. All data is archived.
Full code is here