Home » excel » vba – Code count used Excel Rows but ignores hiddenrows

vba – Code count used Excel Rows but ignores hiddenrows

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am new to VBA with Excel and I want to get the amount of used Rows in my excel sheet.

Currently I am having this Code:

Private Sub

LastRow = Range("A" & Rows.Count).End(xlUp).row
Msgbox LastRow

End Sub

My Problem is that sometimes the Last Rows are hidden(height = 0) but I want the Code to still count them.
How to do this?

Thanks in Advance!

How to&Answers:

Hi you can try below code to find last row even if the row is hidden

Dim WS As Worksheet
Dim LastCell As Range
Set WS = Thisworkbook.Worksheets("Sheet1")
With WS
    Set LastCell = .Columns(1).Find(what:="*", _
        after:=.Cells(.Rows.Count, "A"), _
        LookIn:=xlFormulas, _
        lookat:=xlPart, searchdirection:=xlPrevious)
End With
Debug.Print LastCell.row