Found several similar threads but nothing that seems to address this problem.
If I copy an Excel range into a variant, varArray and then use .SeriesCollection.Values = varArray I get Runtime 1004 error "Unable to set the Values property of the Series class". I've tried first copying the 2D variant into a 1D double or variant to get a 1D array but same message results.
However if I just populate varArray locally with random numbers it works okay. Also I've found that what I originally wanted to do works up to 14 elements in varArray but fails when I increase the size to 15?
Examples of what work and what doesn't below - any guidance much appreciated. (I know I can just use Ranges in the chart but I would prefer not to have to.)
Fails:
varT = Range("T").Offset(1, 0).Resize(, 1).Value
ReDim dT(1 To 15)
ReDim dX(1 To 15)
For i = 1 To 15
dT(i) = varT(i, 1)
dX(i) = i
Next i
varT = dT
varX = dX
Set TheChart = Charts.Add
With TheChart
.Name = sChart
.ChartType = xlXYScatterLines
Set TheSeries = .SeriesCollection.NewSeries
TheSeries.Values = varT
TheSeries.XValues = varX
.....
Works:
varT = Range("T").Offset(1, 0).Resize(, 1).Value
ReDim dT(1 To 14)
ReDim dX(1 To 14)
For i = 1 To 14
dT(i) = varT(i, 1)
dX(i) = i
Next i
varT = dT
varX = dX
Set TheChart = Charts.Add
With TheChart
.Name = sChart
.ChartType = xlXYScatterLines
Set TheSeries = .SeriesCollection.NewSeries
TheSeries.Values = varT
TheSeries.XValues = varX
.....
Works:
ReDim dT(1 To 50)
ReDim dX(1 To 50)
For i = 1 To 50
dT(i) = CDbl(i/2)
dX(i) = i
Next i
varT = dT
varX = dX
Set TheChart = Charts.Add
With TheChart
.Name = sChart
.ChartType = xlXYScatterLines
Set TheSeries = .SeriesCollection.NewSeries
TheSeries.Values = varT
TheSeries.XValues = varX
.....
Bookmarks