I wrote a function to get the last value in a single column in a Google Sheet.
// Returns the row number of the first empty cell
// Offset should be equal to the first row that has data
function getLastRowInColumn(sheet, column, rowOffset) {
var lastRow = sheet.getMaxRows();
for (var row = rowOffset; row < lastRow; row++) {
var range = sheet.getRange(row, column);
if (range.isBlank()) {
return row;
};
}
}
I can assume that all values are filled out, therefore the function is actually returning the first empty cell it finds (in this case, that is equivalent to the first empty row).
The function is taking a long time to run for a sheet with ~1000 rows. How can I make it more efficient?
Thanks in advance.