I keep having issues with visible rows after filtering.
I have a table that looks like this:
The name of the table is tstTBL. I am applying 2 filters: filtering for case ID 3 and Filed = Yes, which gives no results. However, when I count the visible rows, it counts 1, although I use only the databodyrange of the table. I am expecting numRows = 0. How should I change the code?
Sub tstFilter()
Dim filterredRange As Range
Dim tbl As ListObject
Dim caseCol As Integer
Dim trCol As Integer
Dim numRows As Integer
Set tbl = Sheet1.ListObjects("tstTbl")
caseCol = Sheet1.Rows("1:1").Find(What:="Case ID", LookAt:=xlWhole).Column
tbl.Range.AutoFilter Field:=caseCol, Criteria1:=3
'check first filter
On Error Resume Next
Set filterredRange = tbl.ListColumns("Case ID").DataBodyRange.SpecialCells(xlVisible)
On Error GoTo 0
If filterredRange Is Nothing Then
Debug.Print "no such case"
End If
trCol = ActiveSheet.Rows("1:1").Find(What:="Filed", LookAt:=xlWhole).Column
tbl.Range.AutoFilter Field:=trCol, Criteria1:="Yes"
'check second filter
On Error Resume Next
Set filterredRange = tbl.ListColumns("Filed").DataBodyRange.SpecialCells(xlVisible)
On Error GoTo 0
If filterredRange Is Nothing Then
numRows = 0
Else
numRows = filterredRange.Rows.Count
End If
Debug.Print numRows
End Sub