How to jump to last row, when I have empty cells in between?

Viewed 117

When I run the below script, it does not jump into last non empty cell, but it jumps in the middle. I believe I have some empty cells between rows and that is the issue

function onOpen() {
    var s = SpreadsheetApp.getActive().getSheetByName('Raw data')
    s.setActiveRange(s.getRange(s.getRange('A:A').getValues().filter(String).length, 1))
}

enter image description here

See attached screenshot

1 Answers

The issue is because you have empty rows in between the column and filter filters out those rows as well. You can use Sheet#getLastRow() instead of filtering all A:A values:

s.setActiveRange(s.getRange(s.getLastRow(), 1))
Related