Automatically control a pivot table.

Craig_g71

New Member
Joined
Jan 28, 2008
Messages
8
I would like to know if there is a way to automatically control a pivot tables' page field. The pivot table and page field are date based. I would like to control the date of the pivot table from another worksheet of user input method other than the pivot table itself.

Craig G
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Yes, you can do that. You will need VBA. In the worksheet selection change event, check if your date input cell has changed. If so, grab that value and update the pivot table's pivot cache with it, then refresh the pivot table.

Do you know VBA?
 
Upvote 0
I am somewhat familiar wiht VBA. So on the worksheet change event? Is there and event for A pivot table refresh? would I be able to accomplish the same thing when the pivot table refreshes?
 
Upvote 0
To make the change flow from a "control worksheet" to the pivot, yes you'd trap on the worksheet's change event. If you want to flow the other direction then you need to trap on the worksheet's PivotTableUpdate event.

Not 100% what you describe, but it's all I have in my pocket at the moment...

Here I had two pivot tables (on the same worksheet) that were identical in all respects except that PT 1 was using the "before" dataset and PT 2 was using the "after" data set so I could compare a scenario. I wanted to be able to change the page field in one PT and have the page field in the other PT stay in sync:
Code:
Option Explicit
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'// synchronize the page fields on both pivots
    Dim s$, ptA As PivotTable, ptB As PivotTable
 
    With Me.PivotTables
        Set ptA = .Item(1)
        Set ptB = .Item(2)
    End With
 
    If ptA.PageFields(1).CurrentPage _
    <> ptB.PageFields(1).CurrentPage Then
        Application.EnableEvents = False
            If Target.Name = ptA.Name Then
                s = ptA.PageFields(1).CurrentPage
                ptB.PageFields(1).CurrentPage = s
            Else
                s = ptB.PageFields(1).CurrentPage
                ptA.PageFields(1).CurrentPage = s
            End If
        Application.EnableEvents = True
    End If
End Sub

Best way to get the general syntax for altering your pivot's page field would be to use the macro recorder.

HTH
 
Upvote 0
thanks for the help so far but no success yet. What i have is a control sheet with a date field, this field is formula driven. When this date is changed I would like the page field on the pivot table to change as well. hope i was more specific enough.
Thanks
 
Upvote 0
Code:
Dim s As String
 
 s = Sheet1.Range("D11")
    
    ActiveSheet.PivotTables("PivotTable1").PivotFields("type").CurrentPage = s

You'll have to test if you try to change to a page that doesn't exist.
 
Upvote 0
Craig,

Sorry I don't have time to provide more in-depth help. Normally for newbies I'll toss a fish or two. For more experienced members I tend to "give fishing lessons" - show them how to help themselves figure things out.

Unfortunately all I have time to do this week is swing by and tell you where the fish are, so to speak.

Based on what you've described thus far, you could probably hook into your worksheet's _Calculate event handler. Pop a static variant in there to hold the old value of your key cell and compare. If you detect a change to the key cell then update the page field in the pivot using the syntax I show above.

Best of luck (hope you land yer "big'un"),
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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