All PivotItems Listing as Hidden or Not Visible

BenW71

New Member
Joined
Apr 19, 2018
Messages
28
I am trying to go through the current pivot filters that are set up on a pivot table and store them so that they can be reapplied with a single button click. The code for all of this is in an add-in if that matters.

When i loop through the pivot fields and check the visible and not visible items, all are showing up as visible = false.

For example for the Project Type pivot field, below are the current selected values...
1704896602738.png


Debugging a bit shows that when i go through this "Project Type" field i show:
VBA Code:
Public Sub TestGetPivotFieldItems()
Dim pf As PivotField, pi As PivotItem, pt As PivotTable


    Set pt = ActiveSheet.PivotTables(1)
    Set pf = pt.PivotFields("Project Type")
    Set pi = pf.PivotItems("EDF")
  
    Debug.Print (ActiveSheet.Name & " -> " & pf.Name & " -> " & pf.Name & " -> " & pi.Name & ".Visible = " & pi.Visible)
    Debug.Print (ActiveSheet.Name & " -> " & pf.Name & " has " & pf.PivotItems.Count & " total items")
    Debug.Print (ActiveSheet.Name & " -> " & pf.Name & " has " & pf.VisibleItems.Count & " visible item which is " & pf.VisibleItems(1).Name)
    Debug.Print (ActiveSheet.Name & " -> " & pf.Name & " has " & pf.HiddenItems.Count & " not visible items")
  
End Sub

Gives the result:
Full Portfolio -> Project Type -> Project Type -> EDF.Visible = False
Full Portfolio -> Project Type has 10 total items
Full Portfolio -> Project Type has 1 visible item which is (All)
Full Portfolio -> Project Type has 10 not visible items

However, in the screenshot you can see that EDF is checked, as are most of the others... I don't know why it doesn't show 2 as not hidden and the other 8 as visible. i can deal with (All) in the code.
 
Seems like a bug to me. Not sure how you'd work round it though.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
It won't work for a page/filter field unfortunately.
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

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