The function bellow returns the first empty row on column A. The sheet became full, I extended it with another 9000 rows, I ran main manually and I got an error, "TypeError: Cannot read property "0" from undefined".
The problem it seems to be that the 1001'th row cannot be read, values[1001] returns nothing, undefined. Am I missing something or am I limited to 1000 rows of data ?
Thank you for reading, here is the code:
function getLastRowNumber(sheetName){
// sheetName: string; returns intege (the last row number based on column A)
var sheet = getSheet(sheetName);
var column = sheet.getRange('A1:A'); // THIS IS THE PROBLEM
var values = column.getValues(); // get all data in one call
// DEBUG
Logger.log(values[1001][0])
var ct = 0;
while (values[ct][0] != "") {
ct++;
}
return (ct);
}
EDIT: Solution: use .getRange('A:A'); instead of the 'A1:A' notation. Thank you @tehhowch for the solution.
"A:A"
? e.g.const values = sheet.getSheetValues(1, 1, sheet.getLastRow(), 1);
orconst values = sheet.getRange("A1:A" + sheet.getLastRow()).getValues();
? – tehhowch