Reputation: 1
I'm trying to plot 6 series of data but I always get a
run time error (1004): invalid parameter
on the fourth series. this code worked on my previous project but the data on that project is larger than this current data (see image below). Please help.
Sub CreateChart()
With ActiveSheet.Shapes.AddChart(Left:=10, Width:=250, Top:=100, Height:=320).Chart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=Range("A2:G5")
.ApplyLayout Layout:=8
.Axes(xlValue).MinimumScale = "0"
.Axes(xlValue).MaximumScale = "4"
.SeriesCollection(1).Values = Range("A2:A5")
.SeriesCollection(1).XValues = Range("B2:B5")
.SeriesCollection(2).Values = Range("A2:A5")
.SeriesCollection(2).XValues = Range("C2:C5")
.SeriesCollection(3).Values = Range("A2:A5")
.SeriesCollection(3).XValues = Range("D2:D5")
.SeriesCollection(4).Values = Range("A2:A5")
.SeriesCollection(4).XValues = Range("E2:E5")
.SeriesCollection(5).Name = Range("F1")
.SeriesCollection(5).Values = Range("A2:A5")
.SeriesCollection(5).XValues = Range("F2:F5")
.SeriesCollection(6).Values = Range("A2:A5")
.SeriesCollection(6).XValues = Range("G2:G5")
End With
End Sub
Upvotes: 0
Views: 26
Reputation: 1625
Your chart SourceData is not parsed as you expect : the result consists in 3 series only. Thus, calling SeriesCollection(4)
fails.
Try by using the PlotBy
argument when setting SourceData to change the way Excel analyze the range :
With ActiveSheet.Shapes.AddChart(Left:=10, Width:=250, Top:=100, Height:=320).Chart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=Range("A2:G5"), PlotBy:=xlColumns
'....
End With
Upvotes: 1