adding new series to a chart in vba

dinotom

Active Member
Joined
Aug 2, 2009
Messages
357
I having trouble adding additional series to an existing chart. What is the proper method? .NewSeries or .Add?

I am currently using something like

For x = 2 to y+1
Set srsNew = ObjChart.SeriesCollection.NewSeries
With srsNew
.Name = "Name"
.XValues = testrange 'already defined earlier in code
.Values = testrange2
.ChartType = xlXYScatterLinesNoMarkers
End With
Next x

The problem is it is changing the plotting axes. How do I get it to plot on the same axes as the primary chart
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
>NewSeries is fine, and your code looks okay.

Is the primary chart a different chart type? Sometimes Excel "helpfully" places different series types on different axes.

Inside the With srsNew/End With block, insert this line:

.AxisGroup = xlPrimary
 
Upvote 0
I had found that already, thank you. How do I set the line style and line color for the added series if they are xy charts? The object tree doesn't show much for mseriescollection
 
Upvote 0
Tom -

I forget what version of Excel you're using. If it's 2003 or earlier, turn on the macro recorder while formatting a dummy chart, or a copy of your main chart. What you want is found under the Series object in the Object Browser. The line is really the Series.Border object, which has LineStyle and Colorindex properties.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,538
Members
449,316
Latest member
sravya

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