Running Chart Formatting macro everytime PivotTable Updates [code]

ExcelMuf

New Member
Joined
Apr 14, 2018
Messages
1
Hi,

Wrote this code to run and format three series everytime a pivot table updates.
With three series I am formatting the colours of all three and the making the third series a secondary axis and a line chart. What am I doing wrong? the macro is not running everytime I select a slice

Code:
[I]Sub SecondaryAxis()[/I]
[I]'[/I]
[I]' SecondaryAxis Macro[/I]
[I]'[/I]

[I]'[/I]
[I]Dim ser As Series[/I]
[I]On Error Resume Next[/I]

[I]ActiveSheet.ChartObjects("Chart 1").Acivate[/I]


[I]Set ser = Nothing[/I]
[I]Set ser = ActiveChart.FullSeriesCollection("Series 1")[/I]
[I]If Not ser Is Nothing Then[/I]
[I]    With ser[/I]
[I]        ser.ChartType = xlColumnClustered[/I]
[I]        ser.AxisGroup = xlPrimary[/I]
[I]    End With[/I]
[I]'Dark Blue[/I]
[I]    With ser.Format.Fill[/I]
[I]        .Visible = msoTrue[/I]
[I]        .ForeColor.RGB = RGB(10, 66, 121)[/I]
[I]        .ForeColor.TintAndShade = 0[/I]
[I]        .ForeColor.Brightness = 0[/I]
[I]        .Transparency = 0[/I]
[I]        .Solid[/I]
[I]    End With[/I]
[I]End If[/I]


[I]Set ser = Nothing[/I]
[I]Set ser = ActiveChart.FullSeriesCollection("Series 2")[/I]
[I]If Not ser Is Nothing Then[/I]
[I]    With ser[/I]
[I]        ser.ChartType = xlColumnClustered[/I]
[I]        ser.AxisGroup = xlPrimary[/I]
[I]    End With[/I]
[I]'Green[/I]
[I]    With ser.Format.Fill[/I]
[I]        .Visible = msoTrue[/I]
[I]        .ForeColor.RGB = RGB(98, 179, 26)[/I]
[I]        .ForeColor.TintAndShade = 0[/I]
[I]        .ForeColor.Brightness = 0[/I]
[I]        .Transparency = 0[/I]
[I]        .Solid[/I]
[I]    End With[/I]
[I]End If[/I]

[I]Set ser = Nothing[/I]
[I]Set ser = ActiveChart.FullSeriesCollection("Series 3")[/I]
[I]If Not ser Is Nothing Then[/I]
[I]    With ser[/I]
[I]        ser.ChartType = xlLine[/I]
[I]        ser.AxisGroup = xlSecondary[/I]
[I]    End With[/I]
[I]    With ser.Format.Fill[/I]
[I]        .Visible = msoTrue[/I]
[I]        .ForeColor.RGB = RGB(235, 48, 20)[/I]
[I]        .ForeColor.TintAndShade = 0[/I]
[I]        .ForeColor.Brightness = 0[/I]
[I]        .Transparency = 0[/I]
[I]        .Solid[/I]
[I]    End With[/I]

[I]End If[/I]

[I]End Sub[/I]


And inserted into Pivot table update as such

Code:
[I]Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)[/I]
[I]SecondaryAxis[/I]

[I]End Sub

'I am doing this to solve the issue of pivot charts "forgetting" formatting everytime a slicer selection is done


[/I]
 
Last edited by a moderator:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top