My goal is to use VBA to dynamically hide all items in a PivotTable field list except for an array of items stored in a separate table. The catch is it's an OLAP cube so I have to use the Cube field method. Also I am only aware of a way to hide specific items. What I want to do is hide everything except specific items.
I am getting an
Application Defined or Object Related Error
on the line with .HiddenItemsList
I know I am way off on syntax but quite lost at this point.
Public Sub FilterRd()
Dim arCC As Variant
Dim pfCostCenterCode As PivotField
Dim PF As PivotField
Dim PI As PivotItem
arCC = Worksheets("CCs").ListObjects("tblCCs").DataBodyRange.Value
arCC = Application.Transpose(arCC)
Set pfCostCenterCode = Worksheets("RDA").PivotTables("PTccs").PivotFields("[DCC].[CCC].[CCC]")
a = Filter_PivotField(pfCostCenterCode, arrCC)
End Sub
Private Function Filter_PivotField(pvtField As PivotField, varItemList As Variant)
Dim i As Long
' On Error GoTo ErrorHandler:
Application.ScreenUpdating = False
With pvtField
.ClearAllFilters
.CubeField.IncludeNewItemsInFilter = True
End With
For i = LBound(varItemList) + 1 To UBound(varItemList)
pvtField.HiddenItemsList = Array("[DCC].[CCC].&" & varItemList(i) & "]")
Next i
ErrorHandler:
MsgBox "Error while trying to process item: " & varItemList(i)
End Function