Check to see if Chart Object Exist

boldcode

Active Member
Joined
Mar 12, 2010
Messages
347
Hello,

I have a command button by the name "cmdTurn" that updates a chart when clicked. I want to create message box that checks the chart to see if a particular legend label exists (e.g., "Profit") then it tells the user that this legend label already exists therefore exit the sub. I'm thinking something like this:

My command button name is: cmdTurn
My chart object name is: chartTurn

Code:
[CODE]If Me.chartTurn.Legend.("Profit") = true
MsgBox ("The Profit legend label already exists,")
then
Exit Sub
Else
execute cmdTurn VBA code I had already wrote
End Sub

-BC
 
Last edited:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What do you mean by a legend 'label'?

The legend of a chart has LegendEntries, is it perhaps a legend 'entry' you want to check for?
 
Upvote 0
You could use something like this to loop through the legend entries of a legend but I can't find out a way to get the name, or text, of the legend entries.
Code:
If Me.chartTurn.HasLegend Then
    For Each lgdent In Me.chartTurn.Legend.LegendEntries
        
    Next lgdent
End If
 
Upvote 0
boldcode, when you cross-post, it is proper etiquette to post a link to the other site(s) so us volunteers don't waste time working on something that may have been solved elsewhere. It allows us to check and not suggest things that were already suggested somewhere else. It's actually better to wait awhile to see if you get a solution before posting your question a second time somewhere else. The moderator here might have more advice or suggestions if this comes to their attention - I'm not sure if there's anything else I should have mentioned.
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,165
Members
451,750
Latest member
dofrancis

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
Back
Top