Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi good morning all, hope you can help me please, i have the code below, which makes a line chart, and i have named my x and y axis, but on the right hand side it says which line is which and is colour coded, one line is called series 1 and the other is called series 2, but i cant see any where in my code where to rename these 2 lines to what i want to call them, please can you advise please?
VBA Code:
Private Sub CommandButton4_Click()
' declare variables for last row and worksheet
Dim lastRow
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("Sheet1")
' get last populated cell in column A
lastRow = sh.Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
On Error Resume Next
ThisWorkbook.Charts.Delete
On Error GoTo 0
Dim ChartSheet1 As Chart
Set ChartSheet1 = Charts.Add
With ChartSheet1
.SetSourceData Source:=Sheets("Sheet1").Range("C2:C" & lastRow & ",D2:D" & lastRow)
.ChartType = xlLineMarkers
ActiveChart.PlotArea.Format.Fill.ForeColor.RGB = RGB(208, 254, 202)
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Miles"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Pace"
.HasTitle = True
.ChartTitle.Text = "Dist / Avg Pace"
End With
Application.ScreenUpdating = True
Unload Me
End Sub