Chart - Series1 and series 2 lines how to name

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,084
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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,120
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Within the With block, you can maybe do
VBA Code:
.SeriesCollection(1).Name = "First name"
.SeriesCollection(2).Name = "Second name"
 

Forum statistics

Threads
1,148,275
Messages
5,745,799
Members
423,974
Latest member
highvoltageacdc

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top