Mightyginger
Programmer
Mastered using a 1D array to generate my chart but I'm now trying to ammend it to use a 2D array now because now I'd like to create a multiple plot chart instead.
1D: Code I had originally to create chart
Sheet1.ChartObjects.Delete
Set Cht = Charts.Add
Set Cht = Cht.Location(Where:=xlLocationAsObject, Name:="Main"
With Cht
.ChartType = xlLine
'This just fills the graph with something (just anything so I can replace data in code below)
.SetSourceData Source:=Sheet2.Cells(1, 1), PlotBy _
:=xlRows
.HasLegend = False
.HasDataTable = False
With .Parent
.Top = Range("Y2"
.Top
.Left = Range("Y2"
.Left
End With
End With
'This bit here fills the chart with the data stored in the arrays earlier.
For Each Ser In Cht.SeriesCollection
Ser.Values = Values
Ser.XValues = Dates
Next Ser
**End of code.
Values and Dates are the original 1D arrays. I just need to know the correct syntax for referring to 2D arrays. My new 2D arrays work and are filled with data but how do I chart Values(1,allthevalues),Values(2,andallthese),..etc. The X-axis is fine - I don't need to use the 2-D dates array for that.
Proposed new code (which doesn't work)
For Each Ser In Cht.SeriesCollection
Do Until Var = Sheet1.cboMain.Value + 1
ActiveChart.SeriesCollection(Var).Values = Values(Var)
Var = Var + 1
Loop
Ser.XValues = Dates
Next Ser
Exit Sub
A little explanation. cboMain is a combobox the value of which is the number of instruments I need to graph. Based on this I need to loop the part for the SeriesCollection. Main line I need help with is
ActiveChart.SeriesCollection(Var).Values = Values(Var)
how do I correctly address Values(1,x),Values(2,x) etc.
Thanks for your help and I hope my post makes sense.
Neil.
1D: Code I had originally to create chart
Sheet1.ChartObjects.Delete
Set Cht = Charts.Add
Set Cht = Cht.Location(Where:=xlLocationAsObject, Name:="Main"
With Cht
.ChartType = xlLine
'This just fills the graph with something (just anything so I can replace data in code below)
.SetSourceData Source:=Sheet2.Cells(1, 1), PlotBy _
:=xlRows
.HasLegend = False
.HasDataTable = False
With .Parent
.Top = Range("Y2"
.Left = Range("Y2"
End With
End With
'This bit here fills the chart with the data stored in the arrays earlier.
For Each Ser In Cht.SeriesCollection
Ser.Values = Values
Ser.XValues = Dates
Next Ser
**End of code.
Values and Dates are the original 1D arrays. I just need to know the correct syntax for referring to 2D arrays. My new 2D arrays work and are filled with data but how do I chart Values(1,allthevalues),Values(2,andallthese),..etc. The X-axis is fine - I don't need to use the 2-D dates array for that.
Proposed new code (which doesn't work)
For Each Ser In Cht.SeriesCollection
Do Until Var = Sheet1.cboMain.Value + 1
ActiveChart.SeriesCollection(Var).Values = Values(Var)
Var = Var + 1
Loop
Ser.XValues = Dates
Next Ser
Exit Sub
A little explanation. cboMain is a combobox the value of which is the number of instruments I need to graph. Based on this I need to loop the part for the SeriesCollection. Main line I need help with is
ActiveChart.SeriesCollection(Var).Values = Values(Var)
how do I correctly address Values(1,x),Values(2,x) etc.
Thanks for your help and I hope my post makes sense.
Neil.