+ Reply to Thread
Results 1 to 2 of 2

Thread: Help reading the selected items in a pivot table page field

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    Denver, CO
    MS-Off Ver
    Excel 2007
    Posts
    1

    Help reading the selected items in a pivot table page field

    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:
    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
    Any help on how I determine which PivotItems are a part of the filter would be appreciated.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Help reading the selected items in a pivot table page field

    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)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0