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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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