Problems Counting Rows Of Filtered Data

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,585
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to get a count of rows of a filtered worksheet. This code is giving me a result of zero even though there are 3 rows of filtered data. Column 2 is my header row.

Code:
Sub inspect1()
    Dim txt_model As String
    Dim wb_catalogue As Workbook
    Dim ws_ifm As Worksheet
    Dim d As Double
    Dim lrow As Double
    
    Set wb_catalogue = ThisWorkbook
    Set ws_ifm = wb_catalogue.Worksheets("IFM (M)")
    
    
    txt_model = InputBox("Enter Model Name: ", "Index")
    If txt_model = "" Then Exit Sub
    With ws_ifm
        .ShowAllData
        .Range("A2").AutoFilter Field:=1, Criteria1:=txt_model
        Stop
        lrow = .UsedRange.Rows.Count
        d = WorksheetFunction.Subtotal(2, .Columns(1))
        Debug.Print d
    
    End With 
    
End Sub

I tried this method:
Code:
Activesheet.Usedrange.SpecialCells(xlCellTypeVisible).Rows.Count

But it was always giving me inaccurate results (always shy one row, which was a row that would only be revealed on scrolling up.). Erred likely because it was only looking at visible cells, and there was always that oner hidden row it could not see.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try:
VBA Code:
Dim rowCount as Long
rowCount = [subtotal(103,A:A)] - 1
 
Upvote 0
Solution
Sorry for the delay in acknowledging your solution mumps. This seems to be working, thank you.
 
Upvote 0

Forum statistics

Threads
1,224,272
Messages
6,177,631
Members
452,786
Latest member
k3calloway

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