I am trying to write a macro that will filter a pivot table. I want to filter out anything that contains one of two values; "Hosting", and "Infrastructure". I am getting an error on the following macro. It will only filter out the first value. I have tried multipe versions and cannot seem to find a way to filter out anythign containing two different values. Any assistance would be appreciated.
Sub testFilter()
Dim PTitle As PivotField
Set PTitle = ActiveSheet.PivotTables(1).PivotFields("Project Title")
With PTitle
.ClearAllFilters
.PivotFilters.Add xlCaptionContains, , "Hosting"
.PivotFilters.Add xlCaptionContains, , "Infrastructure"
End With
End Sub
I error out when I get to the second filter. I can get this to work with one filter, but not to filter out two different values.
Sub testFilter()
Dim PTitle As PivotField
Set PTitle = ActiveSheet.PivotTables(1).PivotFields("Project Title")
With PTitle
.ClearAllFilters
.PivotFilters.Add xlCaptionContains, , "Hosting"
.PivotFilters.Add xlCaptionContains, , "Infrastructure"
End With
End Sub
I error out when I get to the second filter. I can get this to work with one filter, but not to filter out two different values.