![]() |
Extracting data type from variable
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 -- ExcelMonke ----------------------------------------------------------------------- ExcelMonkey's Profile: http://www.excelforum.com/member.php...nfo&userid=522 View this thread: http://www.excelforum.com/showthread.php?threadid=27680 |
Extracting data type from variable
Check out either TypeOf or TypeName()
-- Regards Juan Pablo González "ExcelMonkey" wrote in message ... Is is possible to extract the data type of a variable? For example lets 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 for type? IF X.Type = Comment Then etc -- ExcelMonkey ------------------------------------------------------------------------ ExcelMonkey's Profile: http://www.excelforum.com/member.php...fo&userid=5221 View this thread: http://www.excelforum.com/showthread...hreadid=276807 |
Extracting data type from variable
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 : Is is possible to extract the data type of a variable? For example lets 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 for type? IF X.Type = Comment Then etc |
All times are GMT +1. The time now is 05:25 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com