Count Cells

P

Pedro

Hi
If when I apply a Filter it gives me 5 records, or 7, or whatever number of
records.
What code should I write in order to give me the number of records (rows) ,
5, 7 whatever

thanks
Pedro
 
T

Ture Magnusson

Pedro,

Will this help? Note that this procedure assumes that the first
column of the filtered range doesn't contain any blank cells.

Sub ShowNumberOfRecords()
Dim rng As Range
Set rng = ActiveSheet.AutoFilter.Range.Columns(1)
MsgBox Application.WorksheetFunction.Subtotal(3, rng) - 1
End Sub
 
T

Tom Ogilvy

Another (works with a column where there may be missing values)

msgbox ActiveSheet.AutoFilter.Range.Columns(1) _
.SpecialCells(xlvisible).count-1
 

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