Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,585
- Office Version
- 365
- 2016
- Platform
- 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.
I tried this method:
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.
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.