Home » excel » How to get adress of last non empty cell in a excel using MACROS(VBA)

How to get adress of last non empty cell in a excel using MACROS(VBA)

Posted by: admin April 23, 2020 Leave a comment

Questions:

I want to get the cell address of the last non empty cell within an excel sheet. Basically I want the row and column number/name of the last non empty cell. I have found few ansers to find out the value in the last non empty cell but I need cell adress not contents.

How to&Answers:

For data like:

xsdew

Most people would like to find the Blue cell:

Sub FindBlue()
    Dim rng As Range
    Set rng = Cells.Find(What:="*", After:=Cells(1), SearchDirection:=xlPrevious, searchorder:=xlByRows)
    MsgBox rng.Address(0, 0)
End Sub

If you want the Yellow cell then:

Sub FindYellow()
    Dim rng As Range
    Set rng = Cells.Find(What:="*", After:=Cells(1), SearchDirection:=xlPrevious, searchorder:=xlByColumns)
    MsgBox rng.Address(0, 0)
End Sub