Solved

What control would I use to get chart selection?

Posted on 2011-03-04
8
274 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
 
LVL 30

Expert Comment

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

Sid
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now