+ Reply to Thread
Results 1 to 6 of 6

Unable to set the currentpage property of the pivotfield class

Hybrid View

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    Canton, OH
    MS-Off Ver
    Excel 2007
    Posts
    10

    Unable to set the currentpage property of the pivotfield class

    I've created a combo box to control the same filter on 4 different pivot tables on one worksheet.
    I've assigned a Macro to the combo box. The code in the Macro is as follows:

    
    Sub Sales_Rep_Combo_Filter()
    '
    ' Sales_Rep_Combo_Filter Macro
    '
    
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Sales Rep").CurrentPage = Range("AA1").Text
        
        ActiveSheet.PivotTables("PivotTable2").PivotFields("Sales Rep").CurrentPage = Range("AA1").Text
        
        ActiveSheet.PivotTables("PivotTable3").PivotFields("Sales Rep").CurrentPage = Range("AA1").Text
        
        ActiveSheet.PivotTables("PivotTable4").PivotFields("Sales Rep").CurrentPage = Range("AA1").Text
        
       End Sub
    When I select a field from the combo box, I get the error in the title of the thread (Unable to set the currentpage property of the pivotfield class).

    Note: The cell reference for the combo box is AA1.

    Any help on this error would be greatly appreciated.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Unable to set the currentpage property of the pivotfield class

    hi, adoepker, can you post sample workbook supporting your problem?

  3. #3
    Registered User
    Join Date
    06-08-2011
    Location
    Canton, OH
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Unable to set the currentpage property of the pivotfield class

    Here's an example file that illustrates the problem I'm running into. When I change the Sales Rep name in the Combo box, I want the Sales Rep Name to change in the Sales Rep filter for each of the 4 Pivot Tables.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Unable to set the currentpage property of the pivotfield class

    hi, for pivottable2 as an example, I would suggest to do it this way:
    Sub pt_2()
    On Error Resume Next: Application.ScreenUpdating = False
    For Each Pi In ActiveSheet.PivotTables("PivotTable2").PivotFields("Sales Rep").PivotItems
        If Pi.Name <> [aa1] Then Pi.Visible = False Else Pi.Visible = True
    Next: Application.ScreenUpdating = True: End Sub

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Unable to set the currentpage property of the pivotfield class

    Try this:
    
    Sub Sales_Rep_Combo_Filter()
    '
    ' Sales_Rep_Combo_Filter Macro
    '
        Dim n As Long
        Dim pt As PivotTable
        For n = 1 To 4
            Set pt = ActiveSheet.PivotTables("PivotTable" & n)
            With pt.PivotFields("Sales Rep")
                If .Orientation = xlPageField Then
                    .CurrentPage = Range("AA1").Text
                ElseIf .Orientation = xlRowField Then
                    pt.ManualUpdate = True
                    .ClearAllFilters
                    .PivotFilters.Add xlCaptionEquals, , Range("AA1").Text
                    pt.ManualUpdate = False
                End If
            End With
        Next n
    End Sub
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    06-08-2011
    Location
    Canton, OH
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Unable to set the currentpage property of the pivotfield class

    Thanks Romperstomper! That works great.

    Watersev, I appreciate the contribution. I tried Romperstomper's first and it worked.

    Is it possible to do something similar for the rest of the filters I have in the example?

    I was just approaching this one step at a time, and the dilemma I ran into with the month filter is that the end user usually is concerned with year-to-date info, so multiple months would have to be selected.

    I have no idea even where to start for writing a code to control the month filters for each pivot table with one combo box/list, and allow for multiple month selections.

    Again, any insight is greatly appreciated. I'm relatively new to this, and I'm learning a lot on the fly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1