Chart Legend Names

A

Andreww

Hi - I have code which, when a user clicks a button, a graph has a
series added to it, then when clicks again it deletes the range.

My series name is incrementally based on which of a series of buttons
is clicked eg if first button is clicked I get series 3 added, 2nd
series 5 and so on.

The series named are based on the button index. The trouble is that as
the legend names are A3, A4,.... A"N" these going to confuse users. (I
add an"A").

The simplest things seems to be to delete the individual legend
entries but VBA doesn't seem to have called the legend entry the same
thing as the series.

Any ideas?

Thanks

Code below:

Sub add_indiv_chart_series()
Dim btn As Button
Dim mText As String
Dim btnText, btnIndex, sitInCell As Variant

'Find out which button clicked
btnIndex = ActiveSheet.Buttons(Application.Caller).Index

' Add chart series on click - if button text is "+" adds series if
"-" deletes
If ActiveSheet.Buttons(Application.Caller).Text = "+" Then
ActiveSheet.ChartObjects("Chart 58").Activate

With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("D" & btnIndex + 4 & ":O" &
btnIndex + 4)
.Name = "=""A" & btnIndex & """"
End With

ActiveChart.SeriesCollection("A" & Trim(Str(btnIndex))).Select
With Selection.Border
.ColorIndex = btnIndex
.Weight = xlThick
.LineStyle = xlContinuous
End With

With Selection
.MarkerBackgroundColorIndex = 2
.MarkerForegroundColorIndex = 3
.MarkerStyle = xlTriangle
.MarkerSize = 7
End With

' Tried variations on below...
ActiveChart.Legend.LegendEntries(btnIndex-1).LegendKey.Select
Selection.Delete

ActiveSheet.Buttons(Application.Caller).Text = "-"

Range(sitInCell).Select

' delete chart series on small button click
ElseIf ActiveSheet.Buttons(Application.Caller).Text = "-" Then
ActiveSheet.ChartObjects("Chart 58").Activate

ActiveChart.SeriesCollection("A" & Trim(Str(btnIndex))).Select
Selection.Delete

ActiveSheet.Buttons(Application.Caller).Text = "+"

Range(sitInCell).Select

End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top