VBA to set maximum scale on chart secondary scale only

SaraB802

New Member
Joined
Feb 7, 2013
Messages
34
So I tried to research this online and found loads of vba to set all the settings and thought my cut down version below would work, and it didn't!
I keep getting a system error &H80070057 (-2147024809)


Sub ScaleAxes()
Worksheets("PM and Programme view").Select
ActiveSheet.ChartObjects("Chart1").Active
Chart1.Axes(xlCategory, xlSecondary).MaximumScale = Range("AG26").Value

End Sub

If anyone can help to resolve this that would be great!

Thanks
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

goesr

Well-known Member
Joined
Nov 15, 2013
Messages
637
Hi SaraB802 - Please try the code below that worked for me. Remember that Chart 1 has a space and the method is activate.

Code:
Sub ScaleAxes_SaraB802()
 Worksheets("PM and Programme view").Select
' ActiveSheet.ChartObjects("Chart 1").activate
' Chart1.Axes(xlCategory, xlSecondary).MaximumScale = Range("AG26").Value
    ActiveSheet.ChartObjects("Chart 1").activate
    ActiveChart.Axes(xlValue, xlSecondary).Select
    ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = Range("AG26").Value
 End Sub

I found this solution by recording the macro and then modifying as necessary.
 
Last edited:

SaraB802

New Member
Joined
Feb 7, 2013
Messages
34
Hi Goser

When I tried it I got a object required error, when I tried it. My code is:



Worksheets("PM and Programme view").Select
ActiveSheet.ChartObjects("Chart 1").Activate


Chart1.Axes(xlCategory, xlSecondary).MaximumScale = Range("AG26").Value
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue, xlSecondary).Select
ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = Range("AG26").Value

Sorry
 

goesr

Well-known Member
Joined
Nov 15, 2013
Messages
637
Hi SaraB802 - Sorry for the miscommunication. When there is an apostrophe starting a line in VBA code that means that the line is commented out. It is best to copy and paste when trying code when possible. Try the code below. It does work in my test case.

Code:
Sub ScaleAxes_SaraB802()
 Worksheets("PM and Programme view").Select
    ActiveSheet.ChartObjects("Chart 1").activate
    ActiveChart.Axes(xlValue, xlSecondary).Select
    ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = Range("AG26").Value

 End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,108,655
Messages
5,524,131
Members
409,561
Latest member
ay123

This Week's Hot Topics

Top