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.
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