It would be easier if the data was in a range, rather than a table, as you could use advanced filter to achieve what you seem to be after. Try the code below on a copy of your workbook. It assumes the criteria is in cell I4 (as per your original post). 2 codes provided. The first deals with a table, the second with a range.
Sub If_Table()
Dim s As String, a As Range, c As Range
s = [I4]
ActiveSheet.ListObjects(1).AutoFilter.ShowAllData
Set a = ActiveSheet.ListObjects(1).DataBodyRange
For Each c In a.Columns(1).Cells
If c = s Or c.Offset(, 1) = s Then c.EntireRow.Hidden = False Else c.EntireRow.Hidden = True
Next c
End Sub
Sub If_Range()
Dim rCrit As Range
With Range("A1").CurrentRegion
Set rCrit = .Offset(, .Columns.Count).Resize(2, 1)
rCrit.Cells(2).Formula = "=OR(A2=$I$4,B2= $I$4)"
.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
End With
rCrit.Cells(2).ClearContents
End Sub
Bookmarks