Add multiple filter items to a pivot table from a named range

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?

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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It means that none of the items meets the condition, so try to hide all, but you have to leave one item visible. If you hide all you will have the error message.
****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">It means that none of the items meets the condition, so try to hide all, but you have to leave one item visible. If you hide all you will have the error message.</body>
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top