megan947us
New Member
- Joined
- Dec 7, 2018
- Messages
- 2
I want to add multiple filter items to a pivot table, and these filter items are from a named range in the current worksheet
I'm getting the error "Unable to set the Visible property of the PivotItem class". What am I doing wrong?
I'm getting the error "Unable to set the Visible property of the PivotItem class". What am I doing wrong?
Code:
Sub PivotUpdate()
Dim PI As PivotItem
Dim vRNG
vRNG = Application.Transpose(Worksheets("Agreements_Materials").Range("Agreement_Filter"))
ActiveSheet.PivotTables("PivotTable4").PivotFields("[AgreementMaterials].[AgreementNumber].[AgreementNumber]").ClearAllFilters
For Each PI In ActiveSheet.PivotTables("PivotTable4").PivotFields("[AgreementMaterials].[AgreementNumber].[AgreementNumber]").PivotItems
If Len(Join(Filter(vRNG, PI, True, vbBinaryCompare))) = 0 Then
PI.Visible = False
End If
Next PI
End Sub