how do i change the series names in my chart

Boogerbut74

New Member
Joined
Oct 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Right now my series names are from F10 to T10. and i have that in my data set but its just putting each series as series 1 to series 16.

VBA Code:
Sub Test_6()


Dim lastrow As Integer
lastrow = Cells(Rows.Count, 10).End(xlUp).Row

'setting x and y axis
Set yData = ActiveSheet.Range("F11:t" & lastrow)
Set xData = ActiveSheet.Range("D11:D" & lastrow)
Set GraphRange = Union(xData, yData)

'Create a chart
   Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=450, _
    Top:=ActiveCell.Top, _
    Height:=250)





'Give chart some data
  cht.Chart.SetSourceData Source:=GraphRange


'Determine the chart type
cht.Chart.ChartType = xlXYScatterSmooth
 'edits chart detailes
cht.Chart.Axes(xlCategory).MinimumScale = 0
cht.Chart.Axes(xlCategory).MaximumScale = 100

cht.Chart.Axes(xlValue).MinimumScale = 115
cht.Chart.Axes(xlValue).MaximumScale = 140

cht.Chart.Legend.Position = xlLegendPositionBottom
 
  
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Right now my series names are from F10 to T10. and i have that in my data set

Your data set, as defined by your code, starts on row 11, so it's not in your data set. Since you are not using xData or yData, you can simplify (tested on my data)
VBA Code:
Sub Test_6()
    
    Dim lastrow As Integer
    Dim GraphRange As Range
    
    lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 10).End(xlUp).Row
    
    'set chart data range (including series names)
    Set GraphRange = ActiveSheet.Range("D10:T" & lastrow)
    
    'Create a chart
    Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=450, _
    Top:=ActiveCell.Top, _
    Height:=250)
    
    'Give chart some data
    cht.Chart.SetSourceData Source:=GraphRange
    
    'Determine the chart type
    cht.Chart.ChartType = xlXYScatterSmooth
    'edits chart detailes
    cht.Chart.Axes(xlCategory).MinimumScale = 0
    cht.Chart.Axes(xlCategory).MaximumScale = 100
    
    cht.Chart.Axes(xlValue).MinimumScale = 115
    cht.Chart.Axes(xlValue).MaximumScale = 140
    
    cht.Chart.Legend.Position = xlLegendPositionBottom
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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