I have a Google Form that populates a Google Sheet with rider registrations for a local cycling club. The sheet has a filter in place to display only the riders for the current day. This filter action was recorded as a macro and it then triggers each day. All this is working fine. What I need is a script that will purge the sheet of rows older than 30 days based on the timestamp in the first column of each row (even if hidden from human view by the filter). I could then trigger this daily.
Searching StackExchange for similar problems, I had come across this answer from 2015 - https://webapps.stackexchange.com/a/85220
function cleanup() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var values = sheet.getDataRange().getValues();
var today = Date.now()/86400000 + 25569;
for (var i = values.length - 1; i >= 0; i--) {
if (values[i][2] - today > 1) {
sheet.deleteRow(i+1);
}
}
}
This seems close to what I need but relies on having formulae on each row of the sheet to 'help' with detecting the relevant rows. As my sheet is merely a receiver of the form data and grows row by row with new form submissions, I need the function to delete expired row without reference to additional formula (unless it is possible to add a script to append a calculated value as each line of the sheet is populated.
I'd describe myself as a 'dabbler' in scripting at no more than absolute beginner level. Any help much appreciated.