VBA & Line Graphs (SOLVED)

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
I am trying to figure out how to customize the legend in a line chart. I have 4 columns of numbers that I do not/cannot have labels for what the columns are (constantly varying). When VBA builds the chart, the legend is very generic (Series1, etc), I would like to change it to read (Processor 1, Processor 2, etc). All the names for the series are in variables, just not sure how to set the series name to a variable. Thanks!!
This message was edited by dowingc on 2002-10-31 19:36
This message was edited by dowingc on 2002-11-11 00:56
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi dowingc,

Just select the chart, then Chart menu > Source Data... > Series Tab. In the Series listbox select the series you want the legend name for, then enter the range reference for that series' name in the Name refedit box. You can enter a range name (e.g., "=MyYrange") in this box (I assume this is what you were referring to by "variables").
 

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
These charts are all being built automatically with VBA. There are currently approximately 12-15 charts that are made, with the program able to make around 150. I need a way for the program to set the legend as the user isn't going to be able to. I have variables in the code that are what I want the legend to read. Logically, this is what I am trying to do with the code but not sure how to properly do it in excel:

t=range("a" & servernumber).value
chart.series1.legend= t
servernumber=servernumber+1
t=range("a" & servernumber).value
chart.series2.legend=t2

This will loop until a certain condition is met (no more servers, etc)

Thanks!!
 

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi dowingc,

Here's an example that might help:

With ActiveSheet.ChartObjects(1).Chart
For servernumber = 1 To 12
.SeriesCollection(servernumber).Name = Cells(servernumber,1)
Next servernumber
End With
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,924
Members
414,416
Latest member
Nobu

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