Hello all,
I am trying to run a code that filters out only the values in certain cells. But when I try to run the code, I keep on getting " Unable to get the pivotfields property of the PivotTable class. Here is the code:
What am I doing wrong?
I am trying to run a code that filters out only the values in certain cells. But when I try to run the code, I keep on getting " Unable to get the pivotfields property of the PivotTable class. Here is the code:
Code:
Sub FilterPivotItems()
Dim PT As PivotTable
Dim PTItm As PivotItem
Dim FiterArr() As Variant
Dim first As String
Dim second As String
Dim third As String
Dim fourth As String
first = Range("a26").Value
second = Range("a27").Value
third = Range("a28").Value
fourth = Range("a29").Value
' use an array to select the items in the pivot filter you want to keep visible
FiterArr = Array(first, second, third, fourth)
' set the Pivot Table
Set PT = Sheets("Lowest Scores").PivotTables("PivotTable4")
' loop through all Pivot Items in "Value" Pivot field
For Each PTItm In PT.PivotFields("Value").PivotItems
If Not IsError(Application.Match(PTItm.Caption, FiterArr, 0)) Then ' check if current item is not in the filter array
PTItm.Visible = True
Else
PTItm.Visible = False
End If
Next PTItm
End Sub
What am I doing wrong?