VBA return all objects

  • Thread starter Thread starter mark1
  • Start date Start date
M

mark1

I am trying to use an if...then statement to show a
message box. I want to say "if the chart legend contains
this legend entry, then show MessageBox X." What I need
is a way to include all legend entries in my if...then
statement, instead of referencing each one seperately. In
the example below, instead of "...LegendEntries
(1).Font..." I want something like "...LegendEntries
(all).Font..." Is there a way to do this? Many thanks!!

Worksheets("sheet1").ChartObjects(1).Chart _
.Legend.LegendEntries(1).Font.Italic = True
 
How about using some type of loop with your single IF statement.



Public sub Find_Legend()

Sheets("Sheet1").Select

ActiveChart.Select

For i = 1 To ActiveChart.SeriesCollection.Count

If ActiveChart.SeriesCollection(i).Name = "My Legend Entry" Then
MsgBox (ActiveChart.SeriesCollection(i).Name & " Has Been Found")
End If

Next

End Sub



Rolli
 

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

Back
Top