?
Solved

What control would I use to get chart selection?

Posted on 2011-03-04
8
Medium Priority
?
280 Views
Last Modified: 2012-05-11
I'm writing an addin, where the user has to select a chart, and then select a range (two different entries).  What control would I use on a userform to enable the user to select a chart (and get that value - e.g., "Chart 1" on a particular sheet - or for that matter, an active chart on a chart sheet?

Thanks!

Dave
0
Comment
Question by:dlmille
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35039146
You can pop up a message telling the user to select a chart and after that you can use the selection object to interact with the chart?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35039149
For selecting different Range, you can use the RefEdit Control.

Sid
0
 
LVL 42

Author Comment

by:dlmille
ID: 35039150
Possibly - since this is top of mind for you, how would I test the selection to ensure it was a chart they had selected?

Dave
0
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.

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35039191
You can use the TypeName(Selection)

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35039383
Example

'~~> Checks if selection is a valid chart
Sub Sample()
    On Error GoTo Err
    If TypeName(Charts(Selection.Parent.Name)) = "Chart" Then _
    Debug.Print "You have selected a Chart Sheet"
Err:
    If TypeName(Selection) = "ChartArea" Then
        Debug.Print "You have selected a Chart in a Sheet"
    Else
        Debug.Print "Invalid Selection"
    End If
End Sub

Open in new window


Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35039396
Forgot the exit sub before Err:

Sid
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35039470
And to check for the Chart Type.

'~~> Checks if selection is a valid chart
'~~> Also Check for the Chart Type
Sub Sample()
    On Error GoTo Err
    If TypeName(Charts(Selection.Parent.Name)) = "Chart" Then
        On Error GoTo 0
        Debug.Print "You have selected a Chart Sheet"
        Debug.Print "Chart Type :" & ActiveChart.ChartType
    End If
    Exit Sub
Err:
    If TypeName(Selection) = "ChartArea" Then
        Debug.Print "You have selected a Chart in a Sheet"
        Debug.Print "Chart Type :" & ActiveChart.ChartType
    Else
        Debug.Print "Invalid Selection"
    End If
End Sub

Open in new window


Sid
0
 
LVL 42

Author Closing Comment

by:dlmille
ID: 35039515
Thanks again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question