adding series to a chart

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

ok i posted before about this but i didnt explain it
properly

i have a chart that is already done, its a bar chart and
has 100 bars, i would like to add the names to those bars
but it would be a pain to do it 1 by one attaching each
series to a bar. is there a quicker way of doing it ??
 
Well, you can't attach a series to a bar; a bar is a subset of a series.
Do you mean you want to add series names to the bars? If your series
names just happen to be in a contiguous worksheet range (all in one row
or one column), this simple macro will apply them to the series:

Sub ApplyNames()
Dim rng As Range
Dim i As Integer
Dim N As Integer
If Not ActiveChart Is Nothing Then
Set rng = Application.InputBox( _
"Select a range with series names", , , , , , , 8)
If Not rng Is Nothing Then
N = rng.Cells.Count
For i = 1 To N
On Error Resume Next
ActiveChart.SeriesCollection(i).Name = _
rng.Cells(i).Value
On Error GoTo 0
Next
End If
Else
MsgBox "Select a chart and try again"
End If
End Sub

To use this, from Excel press ALT+F11 to open the VB Editor, then choose
Module from the Insert menu. Copy this code and paste it into the new
code module you just created. Return to Excel, press ALT+F8, pick the
ApplyNames macro from the list, and click Run.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
thankyou for your help

ok this did work however the info i need to add is 4
colums across , can it be redone to add a row of 4 colums
to 1 bar for each bar ?
 
The code I supplied works whether the labels are in a row or a column.
If that statement doesn't help, then I really don't understand your
question.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top