0
votes

I'd like to generate a chart in Excel using VB. The chart needs to have two series. One of them should be displayed as values and the other used as x-axis. How can I do that? Additionally, how to set labels for the series?

Here is my code that plots one set of values on chart:

ActiveChart.ChartType = xlXYScatterLines
'this sis displayed as y axis (values)
ActiveChart.SeriesCollection.Add Source:=Worksheets("My label").Range("H8:H11") 

Many thanks

1

1 Answers

1
votes

Give this a try...

Sub AddNewSeries()
    With ActiveChart.SeriesCollection.NewSeries
        .Name = '//Name of Series Goes Here//
        .Values = Worksheets("My Label").Range("H8:H11")
        '// change with range of intended x-axis values
        .XValues = Worksheets("My Label").Range("A8:A11")
        .HasDataLabels = True 
    End With
End Sub

Read more: Quick Excel Chart VBA Examples