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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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