How to "Capture" Records Found Number During AutoFilter

G

Guest

When I do an AutoFilter, the number of records found is usually displayed in
the lower left-hand corner of the window. Say the filter result is 5 of 20
records found. How can I "capture" the 5 and 20 number values in VBA? I
want to use the values elsewhere in a macro. Thanks in advance.
 
D

Dave Peterson

Option Explicit
Sub testme()

Dim TotalRows As Long
Dim VisibleRows As Long

With ActiveSheet.AutoFilter.Range.Columns(1)
'subtract the header from both
TotalRows = .Cells.Count - 1
VisibleRows = .Cells.SpecialCells(xlCellTypeVisible).Count - 1
End With

MsgBox VisibleRows & " of " & TotalRows & " records found"
End Sub
 
T

Tom Ogilvy

Dim tot as Long, vis as Long
tot = Activesheet.Autofilter.Range.Rows.count -1
vis = Activesheet.Autofilter.Range.Columns(1).Specialcells(xlVisible) - 1
msgbox vis & " of " & tot
 

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

Top