Add 3 sets of data to existing graph and then step down to next row and repeat

flynch

New Member
Joined
Apr 3, 2017
Messages
17
Per row, I have the name, the Y value and three sets of X values. For example:

Name, Y value, X value 1, X value 2, X value 3
Name, Y value, X value 1, X value 2, X value 3
Name, Y value, X value 1, X value 2, X value 3
(and so on..)

I am trying to plot each row onto an existing scatter graph (where each name has three sets of points) and then for it to step down to the next row and repeat the same process.

I have the code:
Code:
Sub summaryGraph()
Worksheets("PE summary").ChartObjects(1).Activate
Do While Index < 200
        Call MySummaryGraph(i)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Function MySummaryGraph(I)

With ActiveChart.SeriesCollection.NewSeriesSetsourceData

        .Name = ActiveSheet.Range("AG3")
        .Values = ActiveSheet.Range("AF3")
        .XValues = ActiveSheet.Range("AJ3")
End With
With ActiveChart.SeriesCollection.NewSeries
        .Name = ActiveSheet.Range("AG3")
        .Values = ActiveSheet.Range("AF3")
        .XValues = ActiveSheet.Range("AK3")
End With
With ActiveChart.SeriesCollection.NewSeries

        .Name = ActiveSheet.Range("AG3")
        .Values = ActiveSheet.Range("AF3")
        .XValues = ActiveSheet.Range("AL3")
        End With
End Function


But it is coming up with the error message "Error 91: Object variable or With block variable not set"

I'm really new to vba so if this is completely wrong I apologise!
 
Last edited by a moderator:
Glad to help. :)

Just takes practice!
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Glad to help. :)

Just takes practice!

Don't suppose you know how to clear the series before I run the macro do you? It's a graph which will update every time I press a button. I need to clear the graph apart from the first series before I populate it.

Thanks for your help so far
 
Upvote 0
To leave just the first series:

Code:
Sub summaryGraph()
Dim i as long
Dim n as long
Dim ch as Chart
Set ch = Worksheets("PE summary").ChartObjects(1).Chart
for n = ch.seriescollection.count to 2 step -1
   ch.seriescollection(n).delete
next n
For i = 1 to 64
        Call MySummaryGraph(i + 2, ch)
Next i
End Sub
 
Upvote 0
To leave just the first series:

Code:
Sub summaryGraph()
Dim i as long
Dim n as long
Dim ch as Chart
Set ch = Worksheets("PE summary").ChartObjects(1).Chart
for n = ch.seriescollection.count to 2 step -1
   ch.seriescollection(n).delete
next n
For i = 1 to 64
        Call MySummaryGraph(i + 2, ch)
Next i
End Sub


Once again, you saved my bacon!

Thank you!!!!
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top