All,
I have been using Debra Dalgleish's "Change All Pivot Tables With One Selection" macro, and it has been working fine.
On Friday, I tried to apply it to a number of Pivot Charts and while the data elements were updating correctly, the charts would revert to default format. e.g. chart type back to bar, and all on one axis, instead of multi axis.
If I step into the code and run run it in break mode, the formatting is preserved.
I guess I could hard code the formatting into the macro, but it seems a rather inelegant solution - particularly as formatting is still a work in progress.
Any idea why it might be behaving differently when running normally vs stepping through the code?
Being unable to replicate the problem in break mode - I am unsure how to try and isolate the problem!
Code running is below:
I have been using Debra Dalgleish's "Change All Pivot Tables With One Selection" macro, and it has been working fine.
On Friday, I tried to apply it to a number of Pivot Charts and while the data elements were updating correctly, the charts would revert to default format. e.g. chart type back to bar, and all on one axis, instead of multi axis.
If I step into the code and run run it in break mode, the formatting is preserved.
I guess I could hard code the formatting into the macro, but it seems a rather inelegant solution - particularly as formatting is still a work in progress.
Any idea why it might be behaving differently when running normally vs stepping through the code?
Being unable to replicate the problem in break mode - I am unsure how to try and isolate the problem!
Code running is below:
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
On Error Resume Next
Dim wsMain As Worksheet
Dim ws As Worksheet
Dim ptMain As PivotTable
Dim pt As PivotTable
Dim pfMain As PivotField
Dim pf As PivotField
Dim pi As PivotItem
Dim bMI As Boolean
On Error Resume Next
Set wsMain = ActiveSheet
Set ptMain = Target
Application.EnableEvents = False
Application.ScreenUpdating = False
'change all fields for all pivot tables on active sheet
For Each pfMain In ptMain.PageFields
bMI = pfMain.EnableMultiplePageItems
For Each pt In wsMain.PivotTables
If pt <> ptMain Then
pt.ManualUpdate = True
Set pf = pt.PivotFields(pfMain.Name)
bMI = pfMain.EnableMultiplePageItems
With pf
.ClearAllFilters
Select Case bMI
Case False
.CurrentPage = pfMain.CurrentPage.Value
Case True
.CurrentPage = "(All)"
For Each pi In pfMain.PivotItems
.PivotItems(pi.Name).Visible = pi.Visible
Next pi
.EnableMultiplePageItems = bMI
End Select
End With
bMI = False
Set pf = Nothing
pt.ManualUpdate = False
End If
Next pt
Next pfMain
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub