I have a Google Sheet with thousands of rows of data where dates are entered into Column A in order from top to bottom, with varying numbers of rows for each date, starting on Row 9. I have created a button to run a script which hides all rows except for today's date.
What I'm trying to accomplish now is to hide all entries except for the last two dates on the sheet. This is as far as I got with my current script, but it is still only hiding everything except for today's date:
function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Example");
var v = s.getRange("A:A").getValues();
var today = new Date();
var yesterday = new Date(today.setDate(today.getDate()-1));
today.setHours(0, 0, 0, 0);
for (var i = s.getLastRow(); i > 8; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u < yesterday) {
s.hideRows(i);
}
}
}
}
Why is this not working?