Set Excel Chart so maximum scale of y-axis is at least 100%

bisel

Board Regular
Joined
Jan 4, 2010
Messages
233
Office Version
  1. 365
Platform
  1. Windows
Greetings,

I have a bar graph with the y-axes expressed in percent. The minimum percent value is always 0%. However, the maximum percent value can exceed 100%. Sometimes, depending on the data, if I set the y-axes maximum scale for Auto, the chart may have a scale that is less than 100%. I want to make sure that the y-axes is at least 0% to 100% ... more than 100% is OK.

I am trying this VBA without success. I get a run-time error without specifics. Here is the code ....

Code:
    ChartObjects("percentfunding_chart").Activate
    ActiveChart.Axes(xlValue).MaximumScaleIsAuto = False
    If ActiveChart.Axes(x1Value).MaximumScale < 1 Then
        ActiveChart.Axes(x1Value).MaximumScale = 1
        Else
    ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True
    End If

Appreciate any help.

Thanks,

Steve
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I may have solved my own problem. I added the line to select the axes ...

Code:
    ChartObjects("percentfunding_chart").Activate
    
    ActiveChart.Axes(xlValue).Select

    ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True ' first set to true to allow autoset
    ActiveChart.Axes(xlValue).MaximumScaleIsAuto = False ' then set to false to get the value of maxscale
    testx = ActiveChart.Axes(xlValue).MaximumScale ' test the maxscale
    If textx < 1 Then
        ActiveChart.Axes(xlValue).MaximumScale = 1 ' set max scale to 1 if less than 1
    Else
    ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True ' set maxscale back to auto if 1 or more
    End If
 
Upvote 0
Spoke too soon. This code seems to be working.

Code:
    ChartObjects("percentfunding_chart").Activate
    
    If Sheet2.Range("maxpctfunding") < 1 Then
        ActiveChart.Axes(xlValue).MaximumScale = 1 ' set max scale to 1 if less than 1
    Else
        ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True ' set maxscale back to auto if 1 or more
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
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