Add new series to a chart in VBA

derthorsten

New Member
Joined
Jul 13, 2015
Messages
7
Hi,

I m stuck on a project and would appreciate some help. Currently my macro adds a chart with one series. It works fine, although I guess there is a way to program more efficiently (would be nice to know how :-)).

Code:
ws_data.Activate
With ActiveSheet
Set total = .Range("A11:A" & LastRow & ", T11:T" & LastRow)

Charts.Add
    With ActiveChart
        .ChartType = xlLine
        .HasTitle = True
        .HasLegend = False
        .ChartTitle.Text = "Total"
        .SetSourceData Source:=total
        .Location Where:=xlLocationAsObject, Name:=ShName1
    End With
        
   With ActiveChart.Axes(xlCategory)
        .TickLabels.NumberFormat = "MMMMM/YY"
   End With

   With ActiveChart.Axes(xlValue)
        .MaximumScale = max_total + 1000
        .MinimumScale = min_total - 1000
   End with

   With ActiveChart.Parent
           .Top = Cells(4, 10).Top
           .Left = Cells(4, 10).Left
   End With

How do I add a second series that shares the same Y-Values (Dates) as the existing series? If I declare a name "test" and code sth like

Code:
With ActiveChart.SeriesCollection.NewSeries
   .Name = "Test"
   .SetSourceData = test
End with

Any idea?

Many thanks!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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