View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter[_61_] Peter[_61_] is offline
external usenet poster
 
Posts: 48
Default Row count a filtered sheet

On 5 Feb, 14:39, Tom Ogilvy
wrote:
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- Hide quoted text -


- Show quoted text -


Tom that was brilliant!