rjacmuto32
Member
I have a pivot table with some filters at the top. I would like to use VBA to filter the pivot table by the word in cell A1. I can do this, my only issue is I would like to Filter by Contains in the word A1. Example is the items in the pivot table fiedl are:
Andrew, Lori
Andrew, Tim, Lori
Lori, John
So if cell a1 equals Andrew I want to filter the pivot table for the lines like ANdrew. In this case the first 2 items.
The code I'm using so far is this. It works if the names only have Andrew in it but since they contain multiple it's not working. I'm not sure how to modify the last part below for current page nrcCriteria to be a contains not exact match
Andrew, Lori
Andrew, Tim, Lori
Lori, John
So if cell a1 equals Andrew I want to filter the pivot table for the lines like ANdrew. In this case the first 2 items.
The code I'm using so far is this. It works if the names only have Andrew in it but since they contain multiple it's not working. I'm not sure how to modify the last part below for current page nrcCriteria to be a contains not exact match
Code:
Dim nrcCriteria As String
Sheets("RM exclude reasons").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("Name Indicator"). _
ClearAllFilters
nrcCriteria = Range("A1").Value
If nrcCriteria = "All" Then
ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Name Indicator").ClearAllFilters
Else
ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Name Indicator").CurrentPage = nrcCriteria
End If
End Sub