Up until now, I was using an answer from SF to fetch the last non empty row from a range:
=INDEX( FILTER( A4:D ; NOT( ISBLANK( A4:A ) ) ) ; ROWS( FILTER( A4:A ; NOT( ISBLANK( A4:A ) ) ) ) )
Since I started using it quite often, I opted for a script instead:
/* E.g. GETLASTNECELL(A4:A) */
function GETLASTNECELL(input) {
if (!Array.isArray(input)) {
throw new Error("Must be range")
}
if (input.map(col => col.length).sort()[0] !== 1) {
throw new Error("Range must be a single column")
}
const col = input
.map(row => row[0]) // get value
.filter(val => typeof val !== 'undefined' && val.toString().length > 0) // empty
return col[col.length - 1]
}
The issue is that the function is really slow...Is it just a by-product of Google Scripts lifecycle ? The native formulas approach displays the result in an instant. (Tested on a tiny 40x40 spreadsheet)
Read:
40x40
spreadsheet. I tested your formula and realized that it works only for a single column. If you see the error message you haveError("Range must be a single column")
. How do you execute it? What do you pass as a parameter? – soMarioGETLASTNECELL(A4:A)
– nathan