Hey guys,
I have the following sub and I want to create a chart by reading data from array. Because I don't want to have data in worksheets. However, the sub doesn't work if the array is too big (when n>55).
Can somebody help me? I appreciate your help!
But I don't think there is a way to solve this problem without 'printing' the numbers to the worksheet first.
Public Sub CreateScatterPlot()
Dim xValue() As Double, yValue() As Double
Dim sx As String, sy As String, i As Integer
Dim myChart As Chart, n As Integer
Sheet1.Activate
Sheet1.Cells(1, 1).Select
Set myChart = Charts.Add
With myChart
.ChartType = xlXYScatter
.Location xlLocationAsObject, Sheet1.Name
End With
With ActiveChart
n = 50
ReDim xValue(1 To n) As Double
ReDim yValue(1 To n) As Double
For i = 1 To n
xValue(i) = i ^ 2 + 3
yValue(i) = 2 * i + 1
Next i
sx = xValue(1)
sy = yValue(1)
For i = 2 To n
sx = sx & "," & xValue(i)
sy = sy & "," & yValue(i)
Next i
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.Values = yValue
.XValues = xValue
End With
End With
End Sub
Bookmarks