Newbie here.
I'm trying to create multiple charts (i.e. different chart objects with one graph on each). I found a code on youtube that is linked in the comment that I'm modifying.
For now I want to be able to give StartRow which is a starting point and create a scatter plot of the next 700 rows. Then move to another column and plot that.
The code below does indeed create two chart objects but it is:
The data has the following form:
I'm trying to create multiple charts (i.e. different chart objects with one graph on each). I found a code on youtube that is linked in the comment that I'm modifying.
For now I want to be able to give StartRow which is a starting point and create a scatter plot of the next 700 rows. Then move to another column and plot that.
The code below does indeed create two chart objects but it is:
- Creating multiple graphs on each chart object.
- Selecting the data starting from Row 1 (instead of Row 5)
- Selects x and y values for each graph in the same column.
- The two chart objects are duplicates.
VBA Code:
Sub AddCharts()
'https://www.youtube.com/watch?v=5_p8hltGY4s
Dim StartRow as Integer
StartRow = 5
Dim j As Integer 'columns
For j = 5 To 7
With Worksheets("CVData").Shapes.AddChart.Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.XValues = "=" & ActiveSheet.Name & "!" & _
Range(Cells(StartRow, 4), Cells(StartRow + 700, 4)).Address
.Values = "=" & ActiveSheet.Name & "!" & _
Range(Cells(StartRow, j), Cells(StartRow + 700, j)).Address
End With
.HasLegend = False
End With
Next j
End Sub
The data has the following form: