ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with function VBA existing code. (https://www.excelbanter.com/excel-programming/442366-help-function-vba-existing-code.html)

Cam

Help with function VBA existing code.
 
Hello,

I have 2 pivot tables on the same worksheet. The WCtr field is a user select
field so when a WCtr in pivottable1 choice is selected, I want to automate
the same selection in other pivotable2.
I got the following code, but it didn't update pivot2 when pivot1 is
filtered. Please help with the code. Thanks

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'
' Macro created 5/18/2009 by ge295c
'
Dim source As PivotTable
Dim text As String

'check which table changed, we'll make the same change to the other
If Target.Name = "PivotTable1" Then
Set source = PivotTables("PivotTable2")
Else
Set source = PivotTables("PivotTable1")
End If

Application.EnableEvents = False

text = Target.PivotFields("WCtr").CurrentPage
source.PivotFields("WCtr").CurrentPage = text

Application.EnableEvents = True

End Sub

Bob Umlas, Excel MVP

Help with function VBA existing code.
 
Have a look he
http://www.datapigtechnologies.com/f...s/pivot10.html

"Cam" wrote:

Hello,

I have 2 pivot tables on the same worksheet. The WCtr field is a user select
field so when a WCtr in pivottable1 choice is selected, I want to automate
the same selection in other pivotable2.
I got the following code, but it didn't update pivot2 when pivot1 is
filtered. Please help with the code. Thanks

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'
' Macro created 5/18/2009 by ge295c
'
Dim source As PivotTable
Dim text As String

'check which table changed, we'll make the same change to the other
If Target.Name = "PivotTable1" Then
Set source = PivotTables("PivotTable2")
Else
Set source = PivotTables("PivotTable1")
End If

Application.EnableEvents = False

text = Target.PivotFields("WCtr").CurrentPage
source.PivotFields("WCtr").CurrentPage = text

Application.EnableEvents = True

End Sub



All times are GMT +1. The time now is 11:29 PM.

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