Determine last row while autofilter is activated

  • Thread starter Thread starter Ixtreme
  • Start date Start date
I

Ixtreme

Hi,

How can I quickly determine the last row on my sheet while autofilter
is still active?
 
Does something like this not work?

Dim aWS As Worksheet
Dim lRow as long

Set aWS = ActiveSheet

Set myrange = aWS.Rows(aWS.Rows.Count)
lrow = myrange.End(xlUp).Row
Debug.Print lrow
 
You could look at the last visible area and then look at the last cell in that
area:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myRow As Long

With Worksheets("sheet1")
With .AutoFilter.Range.Columns(1).Cells.SpecialCells(xlCellTypeVisible)
With .Areas(.Areas.Count)
myRow = .Cells(.Cells.Count).Row
End With

MsgBox myRow

'maybe a check
If myRow = .Row Then
MsgBox "only headers are visible"
End If
End With
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top