98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Changing of Pivots - Anthony
Changing of Pivots - Anthony
Resolved · Urgent Priority · Version 2007
Mark has attended:
Excel VBA Intro Intermediate course
Excel Advanced - For Power Users course
Excel PowerPivot course
Excel Dashboards for Business Intelligence course
Changing of Pivots - Anthony
I have this code that works across all pivots that I need it to, however I can't get it to work with multiple items.
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim wsOther As Worksheet
Dim pt As PivotTable
Dim pt1 As PivotTable
Dim pt2 As PivotTable
Dim pt3 As PivotTable
Dim pt4 As PivotTable
Dim pt5 As PivotTable
Dim pt6 As PivotTable
Dim pt7 As PivotTable
Dim pt8 As PivotTable
Dim pt9 As PivotTable
Dim pt10 As PivotTable
Dim pt11 As PivotTable
Dim pt12 As PivotTable
Dim pt13 As PivotTable
Dim pt14 As PivotTable
Dim pt15 As PivotTable
Dim pt16 As PivotTable
Dim pt17 As PivotTable
Dim pt18 As PivotTable
Dim pt19 As PivotTable
Dim pt20 As PivotTable
Dim pt21 As PivotTable
Dim pt22 As PivotTable
Dim pt23 As PivotTable
Dim pt24 As PivotTable
Dim pt25 As PivotTable
Dim pt26 As PivotTable
Dim pt27 As PivotTable
Dim pt28 As PivotTable
Dim pt29 As PivotTable
Dim pt30 As PivotTable
Dim pt31 As PivotTable
Dim pt32 As PivotTable
Dim pt33 As PivotTable
Dim pt34 As PivotTable
Dim pt35 As PivotTable
Dim pt36 As PivotTable
Dim pf1 As PivotField
Dim strField1 As String
strField1 = "Month"
Set wsCAMA = Sheet14
Set wsEBC = Sheet9
Set wsCAMO = Sheet4
Set wsSPF = Sheet5
Set wsACR = Sheet23
Set wsPSM = Sheet3
Set wsESA = Sheet22
Set wsOMA = Sheet16
Set wsOOT = Sheet15
Set wsSAG = Sheet21
Set pt = Me.PivotTables("Pivottable1")
Set pt1 = wsCAMA.PivotTables("pivotTable5")
Set pt2 = wsCAMA.PivotTables("pivotTable2")
Set pt3 = wsCAMA.PivotTables("pivotTable8")
Set pt4 = wsCAMA.PivotTables("pivotTable9")
Set pt5 = wsCAMA.PivotTables("pivotTable6")
Set pt6 = wsCAMA.PivotTables("pivotTable12")
Set pt7 = wsEBC.PivotTables("pivotTablebell1")
Set pt8 = wsEBC.PivotTables("pivotTablebell1a")
Set pt9 = wsCAMO.PivotTables("pivotTable11")
Set pt10 = wsCAMO.PivotTables("pivotTable2")
Set pt11 = wsCAMO.PivotTables("pivotTable1")
Set pt12 = wsCAMO.PivotTables("pivotTable6")
Set pt13 = wsCAMO.PivotTables("pivotTable5")
Set pt14 = wsSPF.PivotTables("pivotTable1")
Set pt15 = wsSPF.PivotTables("pivotTable10")
Set pt16 = wsSPF.PivotTables("pivotTable3")
Set pt17 = wsSPF.PivotTables("pivotTable7")
Set pt18 = wsSPF.PivotTables("pivotTable5")
Set pt19 = wsSPF.PivotTables("pivotTable6")
Set pt20 = wsACR.PivotTables("pivotTable1")
Set pt21 = wsACR.PivotTables("pivotTable2")
Set pt22 = wsPSM.PivotTables("pivotTable24")
Set pt23 = wsPSM.PivotTables("pivotTable2")
Set pt24 = wsPSM.PivotTables("pivotTable3")
'Set pt25 = wsESA.PivotTables("pivotTable17")
'Set pt26 = wsESA.PivotTables("pivotTable18")
Set pt27 = wsOMA.PivotTables("pivotTable7")
Set pt28 = wsOMA.PivotTables("pivotTable8")
Set pt29 = wsOMA.PivotTables("pivotTable10")
Set pt30 = wsOMA.PivotTables("pivotTable9")
Set pt31 = wsOMA.PivotTables("pivotTable1")
Set pt32 = wsSAG.PivotTables("pivotTablespp")
Set pt33 = wsSAG.PivotTables("pivotTable2")
Set pf1 = pt.PivotFields(strField1)
On Error Resume Next
If LCase(pt.PivotFields(strField1).CurrentPage) <> LCase(mvPivotPageValue1) Then
Application.EnableEvents = False
pt.RefreshTable
mvPivotPageValue1 = pt.PivotFields(strField1).CurrentPage
pt1.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt2.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt3.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt4.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt5.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt6.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt7.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt8.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt9.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt10.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt11.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt12.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt13.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt14.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt15.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt16.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt17.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt18.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt19.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt20.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt21.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt22.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt23.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt24.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt25.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt26.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt27.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt28.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt29.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt30.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt31.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt32.PageFields(strField1).CurrentPage = mvPivotPageValue1
pt33.PageFields(strField1).CurrentPage = mvPivotPageValue1
Application.EnableEvents = True
End If
End Sub
RE: Changing of Pivots
Hi Mark
Thanks for getting in touch. What error are you getting when you run this?
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Reset Excel toolbars to default settingsIf you find any of your toolbars in Excel have changed (i.e. they are missing or have extra buttons) then you can reset them to their defaults. |