ActiveX Chart

N

Noah

I am trying to create a chart in a userform that has the following ranges as
X and Y values:
lastcol = Worksheets("A").Cells(1, 2).End(xlToRight).Column
XValues = Range(Cells(1, 2), Cells(1, lastcol))
YValues = Range(Cells(2, 2), Cells(2, lastcol))

However, I can't figure out how to set up the array for the chart. I have
the following code in my userform. Any help would be greatly appreciated.
Thanks!

Sub Chart_1()
Dim Chart1 As ChChart
Dim Series1 As ChSeries
Dim XValues As Variant
Dim YValues As Variant

ChartSpace1.Clear
Set Chart1 = ChartSpace1.Charts.Add
lastcol = Worksheets("Values").Cells(2, 1).End(xlToRight).Column
XValues = Array(Range(Cells(1, 2), Cells(1, lastcol)))
YValues = Array(Range(Cells(2, 2), Cells(2, lastcol)))
Set Series1 = Chart1.SeriesCollection.Add
With Series1
.Type = chChartTypeLine
.SetData chDimCategories, chDataLiteral, XValues
.SetData chDimValues, chDataLiteral, YValues
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top