In my spreadsheet, I have a running script, which is using the getLastRow()
function as an essential part of its logic.
Ever since I applied the array formula in one of my columns, the getLastRow()
function doesn't work properly. It seems that the array formula is "applying" all the way to the bottom of the sheet even when there are no other values in the other columns and thus, getLastRow()
is returning the last row where there is an array formula, instead of the actual non-empty row.
Writing a slow function which checks which cells are empty is not an option for me, since the script will run out of time with such thing running (it has tens of thousands of rows).
Does anyone have any suggestions for a workaround?
Here is the ARRAYFORMULA
:
=ArrayFormula(IF(A2:A="",,WEEKNUM(A2:A, 2)))
Here is a function you can use to determine the "true"
lastRow
andlastColumn
values of aSheet
values. It will handle both messyArrayFormula()
and merged cells.Issue:
ARRAYFORMULA()
Solution:
Using
ARRAYFORMULA
properly withINDEX/COUNTA
(to determine the last row that's needed) ensures formula is only filled upto the needed row instead of a camouflageAssuming there are no blanks in between your data,
Another solution is to temporarily remove the ArrayFormulas with
Then calculate lastRow
Then replace the arrayformula