(Solved) – How do you use a two dimensional array to plot a graph in VBA Excel?


I am currently trying to create a dynamic graphing code that reads in 5 arrays and plots them on a scatter line graph. I have made the code and read in the 5 arrays.

I do not know how to apply the data that I have to plot in Excel. I am accomplishing this task in a function. Here is what I have currently:

Function Graph(ByRef int1 As Variant, ByRef int2 As Variant, ByRef int3 As Variant, ByRef int4 As Variant, ByRef int5 As Variant)

Dim c As Chart
Dim srs As Series
Dim xValues As Variant
Dim yValues As Variant

Set c = ActiveChart
'Set srs = cht.SeriesCollection.NewSeries

xValues = Application.Index(int1, 0, 1)
yValues = Application.Index(int1, 0, 2)

With ActiveChart.SeriesCollection
    .xValues = xValues
    .Values = yValues
End With

End Function

I am trying to use a previously existing graph. The code needs to be able to use the currently selected graph and plot the data as indicated.

Let me know if you need any additional information.


Leave a Reply

Your email address will not be published. Required fields are marked *