View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Row count a filtered sheet


Sub CountVisibleRows()
Dim rng As Range, rng1 As Range
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
Set rng1 = rng.SpecialCells(xlVisible)
MsgBox rng1.Count - 1 & " rows are visible"
End Sub




another way is using the Subtotal command. If a specific column will have
values in every row

Sub countvisibleRows2()
Dim rng As Range, cnt As Long
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
cnt = Application.Subtotal(3, rng)
MsgBox cnt - 1 & " rows are visible"
End Sub

--
Regards,
Tom Ogilvy

"Peter" wrote:

I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?

Thanks,

Peter