[INDENT] Sorry, I’ve tried unsuccessfully adapting code posted elsewhere for this…I would like to use VBA to be able to have three named cells determine the min, max and major unit on the y-axis of each of 3 line charts on a worksheet.
In the simple example attached, I have data for three charts, and the charts themselves. The y-axis for each is currently set to auto-scaling.
There are also three named cells, Axis_min, Axis_max, and Major_unit, in which the user would enter the desired values. The user would then click a button and have each of the three charts use the specified y-axis min, max and major unit.
Before posting this I found an explanation of how to do this on John Peltier’s site
http://peltiertech.com/Excel/Charts/…nkToSheet.html
which I have tried to adapt, without success.
The adapted code — which if I can ever get to work — will be triggered by a button on the worksheet, and is as follows:
——————————————
Option explicit
Sub ChangeAxisScales()
With ActiveSheet.ChartObjects(“Chart 1”).Chart
‘ Value (Y) Axis
With .Axes(xlValue)
.MaximumScale = ActiveSheet.Range(“Axis_max”).Value
.MinimumScale = ActiveSheet.Range(“Axis_min”).Value
.MajorUnit = ActiveSheet.Range(“Unit”).Value
End With
End With
End Sub
——————————————–
When I run the macro, however, I get the error message, “Unable to get the ChartObjects property of the worksheet class”.
I’ve no idea what this means. I guess this is what happens when you make a good faith attempt to adapt code when you don’t really understand VBA
If anyone could help me make this work I would be super grateful. [/INDENT]