I am trying to write VBA code to read the values of a page field as set by the user. The field has EnableMultiplePageItems set to TRUE. When I read the CurrentPage property, the item returned is "(All)". It is the only VisibleItems and all of the other PivotItems have Visible set to False. Here is my code:
Any help on how I determine which PivotItems are a part of the filter would be appreciated.Public Function GetPageFilter(Item As String) As String Dim PVT As PivotTable Dim PVfield As PivotField Dim PVitem As PivotItem Dim PVsub As PivotItem Dim PVfilter As PivotFilter Dim Sep As String For Each PVT In ActiveSheet.PivotTables Set PVfield = PVT.PageFields(Item) If PVfield.AllItemsVisible Then GetPageFilter = "(ALL)" Else Set PVitem = PVfield.CurrentPage If PVfield.EnableMultiplePageItems = False Then GetPageFilter = PVitem.Value Else For Each PVsub In PVfield.VisibleItems GetPageFilter = GetPageFilter & Sep & PVsub.Name Sep = " , " Next PVsub End If End If Next PVT End Function
If as implied you're using XL2007, iterate all PivotItems and check Visible status
For Each PVsub in PVfield.PivotItems If PVsub.Visible Then '... End If Next PVsub
It's not clear how you are invoking / utilising the UDF (ie whether or not you need to make it Volatile)
(prior to XL2007 you would need to alter the orientation of the Page Field to that of a Row/Column Field and iterate accordingly)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks