I'm looking to apply a filter to a PivotTable using VBA but I'm stuck on what I hope is a simple error on my part. The source of my pivot data covers ~10000 rows of data, and the column that I'm applying the filter to is called "Mapping Code". I am looking to filter this part of the pivot to only contain data that has "PTC" in the mapping code, but this series of letters can appear anywhere in the Mapping Code. I cannot change the source data in any way as this is in constant use so I need to apply the filter to the PivotTable.
The code that I'm getting an error at occurs here:
The error occurs at the
point in the code.
To be clear, I am looking to apply a filter that contains the letters PTC at any point in the mapping code. When I tried recording the macro to apply the filter it explicitly spelled out the roughly 700 Mapping Codes that do not contain PTC, which is hugely inefficient and not practical (as the Mapping Codes will not be consistent). How should I go about fixing this?
The code that I'm getting an error at occurs here:
VBA Code:
With ActiveSheet.PivotTables("PivotTablePTC").PivotFields("Mapping Codes")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTablePTC").PivotFields("Mapping Codes").CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTablePTC").PivotFields("Mapping Codes")
.PivotItems("*" & "PTC" & "*").Visible = True
End With
The error occurs at the
VBA Code:
.PivotItems("*" & "PTC" & "*").Visible = True
To be clear, I am looking to apply a filter that contains the letters PTC at any point in the mapping code. When I tried recording the macro to apply the filter it explicitly spelled out the roughly 700 Mapping Codes that do not contain PTC, which is hugely inefficient and not practical (as the Mapping Codes will not be consistent). How should I go about fixing this?