kingofaces
Board Regular
- Joined
- Aug 23, 2010
- Messages
- 68
I have a macro I wrote to modify the the axes of a single selected chart (Chartaxis). There are 16 charts in total in this page, and I would like to be able to run a macro that will update the axes of all charts in one go. I tried using the recorder to select the chart and run the Chartaxis macro, and then select the next chart, run macro, etc. Now when I go back and try to run this new macro (Updateallcharts) nothing happens when the charts should be updating. Here's a small snippet of what the code looks like when I tried it with just 4 charts.
This first thing I notice is that three different charts are named Chart 15, so is that causing any issues? Again, if I manually click the chart and run the Chartaxis macro things work just fine. However if I reduce the Updatedallcharts macro to just one chart nothing updates:
It's odd considering this last snippet should be exactly the same as manually clicking one chart and running the Chartaxis macro in practice. Is there some quirk in how VBA interacts with charts that I'm not catching here?
In case it's needed, here's the chartaxis macro:
Code:
Sub Updateallcharts()
ActiveSheet.ChartObjects("Chart 15").Activate
Application.Run "newscptemplate.xlsm!Chartaxis"
ActiveSheet.ChartObjects("Chart 15").Activate
Application.Run "newscptemplate.xlsm!Chartaxis"
ActiveSheet.ChartObjects("Chart 15").Activate
Application.Run "newscptemplate.xlsm!Chartaxis"
ActiveSheet.ChartObjects("Chart 16").Activate
Application.Run "newscptemplate.xlsm!Chartaxis"
End Sub
This first thing I notice is that three different charts are named Chart 15, so is that causing any issues? Again, if I manually click the chart and run the Chartaxis macro things work just fine. However if I reduce the Updatedallcharts macro to just one chart nothing updates:
Code:
Sub Updateallcharts()
ActiveSheet.ChartObjects("Chart 15").Activate
Application.Run "newscptemplate.xlsm!Chartaxis"
End Sub
It's odd considering this last snippet should be exactly the same as manually clicking one chart and running the Chartaxis macro in practice. Is there some quirk in how VBA interacts with charts that I'm not catching here?
In case it's needed, here's the chartaxis macro:
Code:
Sub Chartaxis()
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlValue).MinimumScale = -40
ActiveChart.Axes(xlValue).MaximumScale = 0
With ActiveChart.Axes(xlCategory)
.MinimumScale = 0
.MaximumScale = 6000
.MinorUnit = 500
.MajorUnit = 500
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
End Sub