Extracting data type from variable

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

Is is possible to extract the data type of a variable? For example let
say I have two variables X and Y

Dim X as Comment
Dim Y as Range

I now want to evalute what data type X is. Is their a property fo
type?

IF X.Type = Comment Then

et
 
If you Dim x as comment it would always return "Comment",
wouldn't it?

Sub TypeTest()
Dim x As Object
Dim y As Variant

Set x = ActiveCell
x.Value = 1
y = x.Value

'Typename returns a string with the Class or Type name
If TypeName(x) = "Range" Then Stop
If TypeName(y) = "Double" Then Stop

'TypeOf can be used on objects
'note you use the IS keyword.

If TypeOf x Is Range Then Stop

End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


ExcelMonkey wrote :
 

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