I saw a few different solutions for getting around the 2 wildcard limit for filters in excel (specifically the answer posted here, but I had a hard time understanding what they were doing. The work around I am trying to implement is to just count the number of instances of each criteria in a cell using a basic countif formula, and if it's 0 then the macro will hide the row.
With ws1
ColumnOne = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, lastColumn).End(xlUp).Row
ColumnTwo = ColumnOne - 1
If ws2.Application.WorksheetFunction.CountA("D47:D61") <> 0 Then
For i = 1 To LastRow
If .Cells(i, ColumnTwo).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
ElseIf ws2.Application.WorksheetFunction.CountA("E47:E61") <> 0 Then
For i = 1 To LastRow
If .Cells(i, ColumnOne).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
Else
Exit Sub
End If
End With
The above code is what I'm using to deal with this. For reference, there are two columns of criteria on a separate worksheet (ws2) that can change/be entirely empty. The code above then checks to see which of these columns it should work with (D on ws2 uses ColumnTwo on ws1, E on ws2 uses ColumnOne on ws1) by seeing which one isn't empty, then begins checking the column on ws1 row by row to see if any of the criteria are present. If none of the criteria are present (cell value = 0) then it should hide that row.
The check to use either D or E does not seem to be working. Even when all of the cells in D47:D61 on ws2 are empty it is still operating within that if statement instead of moving to E47:E61. Any ideas as to what I should try and change here?