Creating charts with multiple data series (in a loop)

Ealglez

New Member
Joined
Mar 13, 2015
Messages
28
Dear All,

I am struggling trying to set up a code in VBA to create a chart in the active w/s. This chart should be a scatter line with no markers.
The x values are constant for all the series (column A from A19 - the end will be dynamic).
The y values will vary. The number of series will also be dynamic and all the y values are in columns F19 to end (dynamic), K19... i.e. with an offset of 5 columns.

I have crated the following code but it looks like it overlap the previous series.

Can anyone help please? I am new in VBA and I would really appreciate any input.

Also please not that the name of the series refers to different cells in the w/s (starting in C4 and following with D4, E4, etc.




Code:
Sub inhold()
'Charts of Surge and slug volumes vs. time
                                
                                
Dim lastrow As Long
Dim series As String
Dim counter As Long
Dim s

lastrow = Cells(Rows.Count, "A").End(xlUp).Row


ActiveSheet.Shapes.AddChart2(240, xlXYScatterLinesNoMarkers).Select

counter = 0
Do Until Cells(19, 6).OFFSET(0, 5 * counter) = ""

    Set s = ActiveChart.SeriesCollection.NewSeries()
    With s
        series = "for" & " " & Cells(4, 3).OFFSET(0, 1 * counter)
        ActiveChart.FullSeriesCollection(1).Name = series
        ActiveChart.FullSeriesCollection(1).XValues = ActiveSheet.Range("A19:A" & lastrow)
        ActiveChart.FullSeriesCollection(1).Values = ActiveSheet.Range("F19:F" & lastrow).OFFSET(0, 5 * counter)

    counter = counter + 1
    End With
   
Loop


End Sub
 
Hey!

Finally could come back to this job! I have tried the above and worked fine! Thank you so much again!

E
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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