Help with Chart VBA

mrhuman

New Member
Joined
Sep 14, 2015
Messages
13
I have a chart with column stacked and line from a table of 60 columns and the 59th column alone is the line which cuts the columns something like the image shown. Problem is I have code like this
Code:
 ActiveChart.SeriesCollection(59).ChartType = xlLine
    ActiveChart.Axes(xlValue).MajorGridlines.Select

But if a column in the table is added or deleted I have to manually enter the column number for the line.
Can someone tell me how to make the chart dynamically understand to choose only the second last column for line chart.


barchartpost.png
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,323
Hi,

Code:
ActiveChart.SeriesCollection.Count
[/code
Will tell you the total number of series. So:
[code]
ActiveChart.SeriesCollection(ActiveChart.SeriesCollection.Count-1).ChartType = xlLine
would be one way to do it.

I might try to make it easy for myself and always do that one first so it would always be number 1.

Regards,
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,612
Members
414,080
Latest member
penguin23

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