Create Chart from Array values

Vishesh's picture
This code creates a chart from Array values only. Explore and modify this code to make more complex charts using array only.
Sub CreateChartFromArray()
    Dim objCht As ChartObject
    With Sheet1
        Set objCht = .ChartObjects.Add(10, 20, 500, 200)
        objCht.Chart.ChartWizard .Cells(1)
        objCht.Chart.SeriesCollection(1).Values = Array(56, 61, 45, 15, 30, 10)
        objCht.Chart.SeriesCollection(1).XValues = Array("A", "B", "C", "D", "E", "F")
    End With
    Set objCht = Nothing
End Sub

it does not work

it does not work

Vishesh's picture

Missing line - Code updated

Sub CreateChartFromArray()
Dim objCht As ChartObject
With Sheet1
Set objCht = .ChartObjects.Add(10, 20, 500, 200)
objCht.Chart.ChartWizard .Cells(1)
objCht.Chart.SeriesCollection.NewSeries 'this line is missing in pvs code
objCht.Chart.SeriesCollection(1).Values = Array(56, 61, 45, 15, 30, 10)
objCht.Chart.SeriesCollection(1).XValues = Array("A", "B", "C", "D", "E", "F")
End With
Set objCht = Nothing
End Sub