[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Check whether a named Chart 'Chart_01' is currently selected on the active worksheet

Dear Experts:

I got lots of column charts on the active worksheet.

The Charts are named 'Chart_01', 'Chart_02', 'Chart_03' and so forth.

I would like to have a code snippet with the following requirements:

The macro is to check whether the first chart, i.e. 'Chart_01' is selected. If yes or no, either way, a msgbox has to say so, i.e. either 'Chart_01' is selected or 'Chart_01' is not selected.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
AndreasHermle
Asked:
AndreasHermle
2 Solutions
 
krishnakrkcCommented:
HI,

Something this would help you

Dim chtChart  As Chart
   
    On Error Resume Next
    Set chtChart = ActiveChart
    On Error GoTo 0
   
    If Not chtChart Is Nothing Then
        MsgBox "Activechart's Name is " & Trim$(Replace(chtChart.Name, ActiveSheet.Name, ""))
    Else
        MsgBox "No chart selected ", vbInformation
    End If

Kris
0
 
m4trixCommented:
Sub isChart1Selected()
    If Selection.Parent.Name = ActiveSheet.Name & " Chart_01" Then
        MsgBox "Chart_01 is selected"
    Else
        MsgBox "Chart_01 is NOT selected"
    End If
End Sub

Works in Excel 2010
0
 
AndreasHermleAuthor Commented:
Dear both,

thank you very much for your swift response. I will check you codes tomorrow and then get back to you with a feedback.

Regards, Andreas
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
AndreasHermleAuthor Commented:
Hi m4trix,

yours is working just fine. Thank you very much.

Hi Kris, I am afraid to tell you that yours is somehow not working. Any idea why.

Regards, Andreas
0
 
Saqib Husain, SyedEngineerCommented:
Hi Andreas, although I am not working on this one, a piece of advice is that "not working" does not help as far as troubleshooting is concerned. You could help Kris by specifiying where and how it does not work. Does not work could mean any or more of

- Runs but gives no results
- Runs and gives results but the results are wrong
- There are errors before running the code
- Runs but breaks (in which case you should specify the line number where it breaks)
0
 
AndreasHermleAuthor Commented:
Dear ssagibh:

you are absolutely right. I was in a hurry and did not specify where and how it does not work. Sorry about that!

And moreover, checking on Kris' code again, I noticed that his code works as well. I inadvertently ran another code instead of Kris' macro.

I really appreciate the professionalism of all  of you.

Regards, Andreas
0
 
AndreasHermleAuthor Commented:
Hi Kris and m4trix:

both code work just fine and use different approaches. This is a good way to learn from you.

Thank you very much for your professional support.

Regards, Andreas
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now