calandrelli
Technical User
In Excel if you create a pivot chart and add custom formatting to one of the series, Excel resets it back to default each time you change a data selection. This is troublesome, especially with data that you wish to display using two axes. Microsoft states that this is a known issue and suggests recording a macro of your formatting. Although this was a good starting place they don't go any further.
Most users don't want to run a macro after they update the chart. They want the update to be seamless. I decided that attaching the recorded format code to a chart event would be the best idea, but I was wrong because the only event that would capture a data selection would be "Calculate". Unfortunately, code to change the chart in the change event causes an infinite loop.
The Solution:
The Pivot Table updates every time the Pivot Chart changes so the Worksheet_PivotTableUpdate event can be used to fire off the Pivot Chart formatting.
The following code changes the chart type to a dual axis chart and adjusts the primary axis scale to 0-100 and the secondary axis scale to 0-1.
I hope this example helps.
Most users don't want to run a macro after they update the chart. They want the update to be seamless. I decided that attaching the recorded format code to a chart event would be the best idea, but I was wrong because the only event that would capture a data selection would be "Calculate". Unfortunately, code to change the chart in the change event causes an infinite loop.
The Solution:
The Pivot Table updates every time the Pivot Chart changes so the Worksheet_PivotTableUpdate event can be used to fire off the Pivot Chart formatting.
The following code changes the chart type to a dual axis chart and adjusts the primary axis scale to 0-100 and the secondary axis scale to 0-1.
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Charts("Chart3").Activate
With ActiveChart
.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column on 2 Axes"
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 100
.Axes(xlValue, xlSecondary).MinimumScale = 0
.Axes(xlValue, xlSecondary).MaximumScale = 1
End With
End Sub
I hope this example helps.