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?
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?