Count Filtered row

gnissen

New Member
Joined
Jun 27, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi all
When you apply a filter, what is the code to just count the lines displayed and ignore the hidden rows
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What are you counting specifically?
The SUBTOTAL function with the first parameter starting with 100+ ignores the hidden rows. See MS Documentation.
 
Upvote 0
Hi I am filtering out a part number and showing all data along that row, sometimes there can be 10 rows of data but from different locations. All I would like to do is count those 10 row that are displayed. But it's counting all rows hidden and viewable.
Regards
Greg
 
Upvote 0
You can try this. Select the range you want to count then run the macro.
VBA Code:
Sub VisibleRowsInSelection()
    Dim rng As Range
    Dim c As Range
    Dim rowCount As Long
    Dim uniqueRows As Collection
    
    Set uniqueRows = New Collection
    
    On Error Resume Next
    For Each c In Selection.SpecialCells(xlCellTypeVisible)
        uniqueRows.Add c.Row, CStr(c.Row)
    Next c
    On Error GoTo 0
    
    rowCount = uniqueRows.Count
    MsgBox "Number of visible rows: " & rowCount
End Sub
 
Upvote 0
Sub VisibleRowsInSelection() Dim rng As Range Dim c As Range Dim rowCount As Long Dim uniqueRows As Collection Set uniqueRows = New Collection On Error Resume Next For Each c In Selection.SpecialCells(xlCellTypeVisible) uniqueRows.Add c.Row, CStr(c.Row) Next c On Error GoTo 0 rowCount = uniqueRows.Count MsgBox "Number of visible rows: " & rowCount End Sub
Good morning and thank you for your reply, unfortunately this is not quite what i am after. As per the image attached, when i filter my sheet and i am left with the result, i would like to count the lines and display it in Range("G2").value every time the reset my sheet
 

Attachments

  • Untitled.png
    Untitled.png
    30.9 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,221,563
Messages
6,160,508
Members
451,654
Latest member
DIIA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top