In my example sheet, I'm using this script provided by @Rene Olivio to hide all rows containing older dates than the rows containing the two most recent dates in Column A:
function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Example");
var v = s.getRange("A:A").getValues();
var lastDate = s.getRange("Example!A"+ s.getLastRow()).getValue();
var previous = lastDate
var counter = 0
for(var i = s.getLastRow(); i > -1; i--) {
if ((v[i][0]).toString() !== previous.toString()){
counter = counter + 1
previous = (v[i][0])
var row = i
if (counter == 4){
break
}
}
}
s.hideRows(9,row-7)
}
While this is working great when there is no data in any of the rows without dates in the first cell, I require all cells in both Columns P and Q to contain empty checkboxes. When this is the case however, I get the error message: TypeError: Cannot read properties of undefined (reading '0')
.
How would I best update the getLastRow function to avoid looking at cells other than Column A?