View Single Post
  #2  
Old August 17th, 2009, 03:50 PM posted to microsoft.public.excel.charting
Luke M
external usenet poster
 
Posts: 2,672
Default How do I find the series associated with a given legend entry.

We can hide a specific series by controlling the PlotOrder. If we make the
target series plotOrder = 1, then we can delete legend entry 1. Then, restore
plot order to what it was before. Note that this macro assumes chart is
already activated, but I presume you can figure out how to code that part.

Sadly, it also makes the rather large assumption that the legend entry has
not already been deleted. But hopefully this gives you a start.

Sub HideName()
Dim NSrs As Integer
Dim CurrentOrder As Integer

'Name of series to hide legend for
xName = "MySeries"

With ActiveChart
NSrs = .SeriesCollection.Count
For i = 1 To NSrs
If .SeriesCollection(i).Name = "Girl" Then
CurrentOrder = .SeriesCollection(i).PlotOrder
.SeriesCollection(i).PlotOrder = 1
.Legend.LegendEntries(1).Delete
.SeriesCollection(i).PlotOrder = CurrentOrder
End If
Next
End With
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"SamW" wrote:


I have a problem, whereby I need to find the association between a legend
entry and a chart series (in order that I can do something with the legend
entry for a specific series if it exists).

I cannot find a way to establish a firm link between a series and its
legend, for instance:

The chart has 5 series.
The legend had 5 series but the user (or something/somebody) deleted 2 of
these legend entries so there are 3 legend entries.

So, at this point lets say I have code which has a specific series in its
hand:
Excel.Series series = _chart.Series(3);

And with this series I want to delete the legend entry:
Excel.LegendEntry entry = _chart.Legend.LegendEntries( entryForSeries3 )

Is there something I am missing here? Or is there a method on an object that
I haven't seen that allows me to get the LegendEntry associated with a series?