Application.Selection Is Range?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I determine if the Application.Selection is a Range type object?
Is there a way test way to test like this:

If Application.Selection Is Range Then
'Then do some thing with the range.
End If
 
Hi Jeff,

Try something like this

Dim rng As Range

On Error Resume Next
Set rng = Application.Selection
On Error GoTo 0
If rng Is Nothing Then
MsgBox "Not a r5ange"
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi,
you can use the TypeName function which returns the 'class' name as a string
of the object or value: in your case, if it is a range
TypeName(Application.Selection) returns "Range". That is :
If TypeName(Application.Selection)="Range" Then
'...
Endif

Regards,
Sebastien
 
Use the TypeOf operator. E.g.,

If TypeOf Selection Is Excel.Range Then
Debug.Print "range"
Else
Debug.Print TypeName(Selection)
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top