Problem adding multiple series in a chart with vba

MickeO

New Member
Joined
Dec 21, 2011
Messages
13
I have a macro that I've been working on for months and I can't get it to work.
I have gotten it to work with the first series, but only the first series in the chart are drawn on the chart.

Here's how the chart looks:
3327yoz.jpg

Here's the code to draw the chart (Excel 2010):
Code:
Sub EmbeddedChartFromScratch(wbM As Workbook, blad As String)
    Dim myChtObj As ChartObject
    Dim rngChtData As Range
    Dim rngChtXVal As Range
    Dim iColumn As Long
 
    ' Using the selected range as the chart's data source.
    ' The first row contains the series labels, the first column contains the X values,
    ' and the rest of the columns contain the Y values for each series.
    ' make sure a range is selected
    If TypeName(Selection) <> "Range" Then Exit Sub
    ' define chart data
    Set rngChtData = Selection
    ' define chart's X values
    With rngChtData
        Set rngChtXVal = .Columns(1).Offset(1).Resize(.Rows.Count - 1)
    End With
    ' add the chart
    Set myChtObj = ActiveSheet.ChartObjects.Add(Left:=150, Width:=300, Top:=15, Height:=300)
    With myChtObj.Chart
        ' make an line chart
        .ChartType = xlLine
        ' remove extra series
        Do Until .SeriesCollection.Count = 0
            .SeriesCollection(1).Delete
        Loop
        ' add series from selected range, column by column
        For iColumn = 2 To rngChtData.Columns.Count
            With .SeriesCollection.NewSeries
                .Values = rngChtXVal.Offset(, iColumn - 1)
                .XValues = rngChtXVal
                .Name = rngChtData(1, iColumn)
            End With
        Next
    End With
End Sub

Code addapted from example at http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I found why the chart isen't drawn as intended. I use a "," in the values, if I change it to "." it is output correctly,
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,852
Members
449,471
Latest member
lachbee

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