Thanks Andy,
Have I done something wrong here? It does not seem to want to plot when I change the code to denote one column as you suggest above.
I have also added a title and axis labels to the code, which seems to be working ok.
Thanks again for your help.
Cheers,
Matt
Public Sub CreateChart_SingleCol()
Dim RowIndex As Long
Dim XData As Range
Dim YData As Range
Dim NameData As Range
Dim Cht As Chart
' reference data
Set NameData = Range("A3", Range("A3").End(xlDown))
Set YData = NameData.Offset(0, 1).Resize(NameData.Rows.Count, 1)
Set XData = YData.Offset(0, 1)
' get chart and remove existing data
Set Cht = ActiveSheet.ChartObjects(1).Chart
With Cht
Do While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Loop
' add rows of data
For RowIndex = 1 To NameData.Rows.Count
With .SeriesCollection.NewSeries
.Name = "='" & NameData.Parent.Name & "'!" & NameData.Cells(RowIndex, 1).Address(xlR1C1)
.Values = "='" & YData.Parent.Name & "'!" & YData.Rows(RowIndex).Address(xlR1C1)
.XValues = "='" & XData.Parent.Name & "'!" & XData.Rows(RowIndex).Address(xlR1C1)
With .Format.Line
.EndArrowheadStyle = msoArrowheadTriangle
.ForeColor.RGB = 5296274 ' green
.Weight = 1
End With
.Smooth = True
End With
Next
' Set Chart Title
.HasTitle = True
.ChartTitle.Text = ActiveSheet.Cells(1, 1)
' Set Axis Title
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Text = ActiveSheet.Cells(1, 3)
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Text = ActiveSheet.Cells(1, 2)
End With
End Sub
Bookmarks