The code needs to delete rows have a date before the current date. I'm not getting any syntax errors, but I think there is a semantic problem as the code will not change the spreadsheet in any way.
function checkDateValue(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var todaysDate = new Date().getDate();
var columnGCells = sheet.getRange("G2:G");
var columnG = columnGCells.getValues();
for (i = 1; i < sheet.height; i++) {
var endDate = new Date()
endDate = columnG[i];
if (todaysDate.getYear() >= endDate.getYear()){
if (todaysDate.getMonth() >= endDate.getMonth()){
if (todaysDate.getDay >= endDate.getDay()){
sheet.deleteRow(i);
}
}
}
}
};
checkDateValue();
height
property of a sheet. Use thegetLastRow()
method. But, you'll still have a problem even if you change that. To delete rows, you need to iterate from the bottom up. Instead of an increment counteri++
you need to decrementi--
. – Alan Wells