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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,123
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"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,580
Messages
5,770,976
Members
425,654
Latest member
Kotika

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