possible to CHANGE Y AXIS ON CHARTS WITH VBA?

erickguz

Board Regular
Joined
May 11, 2010
Messages
58
Hello,

I tried some vba examples but couldn't quite get the following to work.

I have about 50 charts per sheet on a worksheet.

Is it possible to change the y axis for the 50 sheets on a sheet with vba, without affecting the other sheets?

Right now for example, I have

MIN: 0
MAX: 50
MAJOR UNIT: 25

need to change to:

MIN: 2000
MAX: 5000 (or auto)
MAJOR UNIT: 500

Thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yes it is possible. What code did you try, and what happened?

It's basically a loop like this:

Code:
dim oCht as chartobject
for each ocht in sheets("sheet name").chartobjects
With ocht.chart.axes(xlValue, xlPrimary)
      .MaximumScale = 5000
      .MinimumScale = 2000
      .MajorUnit = 500
    End With
next ocht
 
Upvote 0
Thanks Rory, This worked very well for the charts that I needed changed. I had a code that i got off a random site but it was about a page long... It just made everything zero - not sure honestly, I'm not new to excel, just not familiar with vba

Is it possible to adjust this code and create separate macros?

1. have a macro that works only on selected charts

2. Make it AUTO maximum and minimum with Major Unit of 500
 
Last edited:
Upvote 0
For 1, remove the loop and use

Code:
With activechart.axes(xlValue, xlPrimary)
      .MaximumScale = 5000
      .MinimumScale = 2000
      .MajorUnit = 500
    End With

for 2, you can use:

Code:
With ocht.chart.axes(xlValue, xlPrimary)
      .MaximumScaleIsAuto = True
      .MinimumScaleIsAuto = True
      .MajorUnit = 500
    End With
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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