Home » excel » excel – How to change the subtype of Chart from VBA code

excel – How to change the subtype of Chart from VBA code

Posted by: admin May 14, 2020 Leave a comment

Questions:

I create charts from some data:

ActiveSheet.Shapes.AddChart2(297, xlColumnStacked).Select

But on Excel there are different subtypes of the xlColumnStacked chart…

d

I need to show the second one, not the default one.

It has to be programmatically, not manually.

I tried to record the macro and see what does the change, but it doesn’t record anything… I tried loading from Templates also but they don’t work exactly like the one I need.

Thanks for your support.

How to&Answers:

I thing you have to change .ChartTyp
for example:

 ActiveChart.ChartType = 52

Here is list of proper Value
https://bettersolutions.com/excel/charts/vba-chart-types.htm

If you want to switch x axis and y axis data try one of this:

ActiveChart.PlotBy = xlColumns

ActiveChart.PlotBy = xlRows

I hope I helped 🙂

Answer:

They both looked like stacked columns. VBA doesn’t have chart subtypes, and controls the chart type using this syntax:

ActiveChart.ChartType = xlColumnClustered
ActiveChart.ChartType = xlColumnStacked
ActiveChart.ChartType = xlColumnClusteredStacked100

VBA’s Object Browser shows you all of the possibilities.