Chart - Series1 and series 2 lines how to name

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. 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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Within the With block, you can maybe do
VBA Code:
.SeriesCollection(1).Name = "First name"
.SeriesCollection(2).Name = "Second name"
 
Upvote 0
That works fantastic thankyou for your advice and help much appreciated
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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
Back
Top