Andy Pope
Posts: n/a
Re: Excel macro for multiple series in a single scatter graph using3 columns
Hi,
This should get you started.
Assumed your data is in A1:C19, including header row.
Sub CreateChart()
Dim lngRow As Long
Dim lngStartRow As Long
Dim objChart As Chart
Dim objSeries As Series
Set objChart = ActiveSheet.ChartObjects.Add( _
100, 100, 400, 250).Chart
objChart.ChartType = xlXYScatterLines
lngStartRow = 2
lngRow = 2
With ActiveSheet
lngStartRow = 2
lngRow = 2
Do While Len(.Cells(lngRow, 1).Value) > 0
If .Cells(lngStartRow, 3) <> .Cells(lngRow, 3) Then
' deal with grouped ID
Set objSeries = objChart.SeriesCollection.NewSeries
objSeries.Name = .Cells(lngStartRow, 3).Value
objSeries.XValues = _
..Range("A" & lngStartRow, "A" & lngRow - 1)
objSeries.Values = _
..Range("B" & lngStartRow, "B" & lngRow - 1)
lngStartRow = lngRow
End If
lngRow = lngRow + 1
Loop
Set objSeries = objChart.SeriesCollection.NewSeries
objSeries.Name = .Cells(lngStartRow, 3).Value
objSeries.XValues = .Range("A" & lngStartRow, "A" & lngRow - 1)
objSeries.Values = .Range("B" & lngStartRow, "B" & lngRow - 1)
lngStartRow = lngRow
End With
End Sub
Cheers
Andy
trumptmast wrote:
> ....Can anyone help me with this? Does anyone need more information?
>
>
--
Andy Pope, Microsoft MVP - Excel
http://www.andypope.info