View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] paul.robinson@it-tallaght.ie is offline
external usenet poster
 
Posts: 789
Default Pivot Table - change page field help

Hi
Each pivottable on a sheet is numbered. If you have 2 on a sheet then
try
Dim pt1 as PivotTable, pt2 as PivotTable
Set pt1 = Worksheets("MySheet").PivotTables(1)
Set pt2 = Worksheets("MySheet").PivotTables(2)

In your code remove the looping and change pt1 and pt2 individually.
This is untested so you may need to fiddle with it a bit.

regards
Paul

On Mar 10, 2:49*pm, Opal wrote:
I have a workbook in Excel 2003 with multiple worksheets.
I want to be able to change the page fields in only one
worksheet, not all the worksheets. *I have found
Debra Dalgleish's website very helpful, but her code is
to change the page field in all pivots in the workbook, I only
want to change the page fields on 2 pivot tables on one sheet.
Could someone please give me some direction as to how
I can modify this code to change only the 2 pivots on
one sheet?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String

strField = "Region"

On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False

* * If Target.Address = Range("D2").Address Then

* * * * For Each ws In ThisWorkbook.Worksheets
* * * * * * For Each pt In ws.PivotTables
* * * * * * * * With pt.PageFields(strField)
* * * * * * * * * * For Each pi In .PivotItems
* * * * * * * * * * * * If pi.Value = Target.Value Then
* * * * * * * * * * * * * * .CurrentPage = Target.Value
* * * * * * * * * * * * * * Exit For
* * * * * * * * * * * * Else
* * * * * * * * * * * * * * .CurrentPage = "(All)"
* * * * * * * * * * * * End If
* * * * * * * * * * Next pi
* * * * * * * * End With
* * * * * * Next pt
* * * * Next ws

* * End If

Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

Thank you....my sheet is FSChart1, pivot tables are PT1 and PT2.