VBA to set min and max values of X-axis for selected charts

ramkumarcn

Board Regular
Joined
Jun 21, 2011
Messages
114
Hi,

I am trying to write VBA to configure the min and max values of X-axis for any chart that accepts this configuration. This is because, min and max values of X-axis cannot be configured for all charts.

The below code sets the min and max values as expected. However, I would like the below code to be executed only when the charts are of type xlBarClustered, xlBarStacked, xlBarStacked100, xl3DBarClustered, xl3DBarStacked, xl3DBarStacked100, xlCylinderBarClustered, xlCylinderBarStacked, xlCylinderBarStacked100, xlConeBarClustered, xlConeBarStacked, xlConeBarStacked100, xlPyramidBarClustered, xlPyramidBarStacked, xlPyramidBarStacked100

With chName.Axes(xlCategory)
.MinimumScale = CtrlSheet.Range("C2").Value
.MaximumScale = CtrlSheet.Range("D2").Value
End With

Can you please help me with this?

Thanks,
Ram
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,890
Office Version
  1. 365
Platform
  1. Windows
Try...

Code:
Select Case chName.ChartType
    Case xlBarClustered, xlBarStacked, xlBarStacked100, xl3DBarClustered, _
        xl3DBarStacked, xl3DBarStacked100, xlCylinderBarClustered, _
        xlCylinderBarStacked, xlCylinderBarStacked100, xlConeBarClustered, _
        xlConeBarStacked, xlConeBarStacked100, xlPyramidBarClustered, _
        xlPyramidBarStacked, xlPyramidBarStacked100
        With chName.Axes(xlCategory)
            .MinimumScale = CtrlSheet.Range("C2").Value
            .MaximumScale = CtrlSheet.Range("D2").Value
        End With
End Select

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,190,646
Messages
5,982,113
Members
439,755
Latest member
nicos18

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
Top