0
votes

I have a set of columns ( column : "C:I" on the excel sheet ) which I want to select the last cells of. The issue is that I can't use xldown because there are some blank cells in the beginning of the columns...

How to effectively select the last row anyway? I'¨m trying Range("C1:I1").rows.end(xldown) but it gets stuck right at the beginning at the last non-empty cell after the empty ones.

2
use xlup that is the usual solution to thiswhytheq

2 Answers

2
votes

If the columns are filled in an irregular fashion, then:

Sub qwerty()
    Dim N As Long, M As Long, mm As Long
    M = 0
    For N = 3 To 9
        mm = Cells(Rows.Count, N).End(xlUp).Row
        If mm > M Then
            M = mm
        End If
    Next N
    Cells(M, 1).EntireRow.Select
End Sub

For example:

see

Note that the attractive:

Sub dural()
    Range("C:I").Cells.SpecialCells(xlCellTypeLastCell).Select
    Selection.EntireRow.Select
End Sub

Will select row #18 by mistake!

2
votes

An example which works on a single column:

Sub findLastCellInColumnA()

Dim lstRow As Integer
lstRow = Cells(Rows.Count, 1).End(Excel.xlUp).Row
Cells(lstRow, 1).Select

End Sub