Solved

What control would I use to get chart selection?

Posted on 2011-03-04
8
276 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
  • 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 41

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 500 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 41

Author Closing Comment

by:dlmille
ID: 35039515
Thanks again!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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