Linking Page Fields for multiple pivot tables

N

nofam

I'm using the following code to set the page field for PivotTable2
based on whatever it's set as in PivotTable1:

Code:

Sub SetPagefield()
Application.ScreenUpdating = False
Dim pfld As PivotField
Dim Pi As PivotItem
Dim Target As Range
Set Target = Worksheets("Chris").Range("B3")

If IsEmpty(Target.Value) Then Exit Sub
Set pfld = Worksheets("Chris").PivotTables _
("PivotTable2").PageFields( _
"Month")

For Each Pi In pfld.PivotItems
If Pi.Value = Target.Text Then
pfld.CurrentPage = Pi.Value
Exit For
End If
Next

Application.ScreenUpdating = True
End Sub

The page fields in question contain month names (January, August etc),
and the code works for these, but doesn't work when I select (All)
from PivotTable1.

What am I doing wrong?
 
N

nofam

Excel 2007 PivotTable
Matchpagefielditem selection
of multiple PTs.http://c0718892.cdn.cloudfiles.rackspacecloud.com/04_10_10.xlsm

Hello Herbert,

Many thanks for posting the link - that's exactly what I want.
However, I'm using the code in Excel 2003, and I still can't get it to
work when I select (All) from the page field - I get a the following
error:

Run-time Error '1004

Unable to set the Visible property of the PivotItem class


Each month is working perfectly though if I select them individually.

Any ideas?

Thanks again for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top