ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Linking Page Fields for multiple pivot tables (https://www.excelbanter.com/excel-programming/441703-linking-page-fields-multiple-pivot-tables.html)

nofam

Linking Page Fields for multiple pivot tables
 
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?

Herbert Seidenberg

Linking Page Fields for multiple pivot tables
 
Excel 2007 PivotTable
Match page field item selection
of multiple PTs.
http://c0718892.cdn.cloudfiles.racks.../04_10_10.xlsm


nofam

Linking Page Fields for multiple pivot tables
 
On Apr 17, 9:57*am, Herbert Seidenberg
wrote:
Excel 2007 PivotTable
Matchpagefielditem selection
of multiple PTs.http://c0718892.cdn.cloudfiles.racks.../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!


All times are GMT +1. The time now is 02:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com