J
jdh
I am trying to create a chart with multiple series in the active worksheet. I
am trying to plot up column A vs B for each series (The Series Name is in
column C). Each series is of varying length, so I loop through the list name
(column C) and compare it to a short set of Series Names in Column F. I am
getting errors with the Set NewSrs statement. Do I have the wrong variable
types defined? Any help would be appreciated.
Dim i, j, k, l As Long
Dim sName, cName, seName As String
Dim oChart As Chart
Dim NewSrs As Series
sName = ActiveSheet.Name
Set oChart = Charts.Add
oChart.ChartType = xlXYScatter
oChart.Location Where:=xlLocationAsObject, Name:=sName
k = 0
For i = 1 To Range(Sheets(sName).Range("C1"),
Sheets(sName).Range("C1").End(xlDown)).Count
If Sheets(sName).Range("C1").Offset(i, 0) =
Sheets(sName).Range("F1").Offset(k, 0) Then
j = j + 1
Else
Set NewSrs = oChart.SeriesCollection.NewSeries
With NewSrs
' Name of the first set of data
.Name = Sheets(sName).Range("F1").Offset(k, 0).Value
' X-Values in the 1st column
.XValues = Sheets(sName).Range(Cells(l + 1, 2), Cells(j , 2))
' Y-Values in the 2nd column
.Values = Sheets(sName).Range(Cells(l + 1, 3), Cells(j , 3))
End With
j = j + 1
k = k + 1
End If
Next i
am trying to plot up column A vs B for each series (The Series Name is in
column C). Each series is of varying length, so I loop through the list name
(column C) and compare it to a short set of Series Names in Column F. I am
getting errors with the Set NewSrs statement. Do I have the wrong variable
types defined? Any help would be appreciated.
Dim i, j, k, l As Long
Dim sName, cName, seName As String
Dim oChart As Chart
Dim NewSrs As Series
sName = ActiveSheet.Name
Set oChart = Charts.Add
oChart.ChartType = xlXYScatter
oChart.Location Where:=xlLocationAsObject, Name:=sName
k = 0
For i = 1 To Range(Sheets(sName).Range("C1"),
Sheets(sName).Range("C1").End(xlDown)).Count
If Sheets(sName).Range("C1").Offset(i, 0) =
Sheets(sName).Range("F1").Offset(k, 0) Then
j = j + 1
Else
Set NewSrs = oChart.SeriesCollection.NewSeries
With NewSrs
' Name of the first set of data
.Name = Sheets(sName).Range("F1").Offset(k, 0).Value
' X-Values in the 1st column
.XValues = Sheets(sName).Range(Cells(l + 1, 2), Cells(j , 2))
' Y-Values in the 2nd column
.Values = Sheets(sName).Range(Cells(l + 1, 3), Cells(j , 3))
End With
j = j + 1
k = k + 1
End If
Next i