VBA data types

There is a bunch of data type we can handle with VBA, but looking at a variable value it will not get us to the type of value it is. From Ms Online help we can get the constant values returned by the function VarType(). So we can make a table like this one:
Data Type Bytes Used Range of Values Const value Constant
Byte 1 0 to 255 17 vbByte
Boolean 2 true or False 11 vbBoolean
Integer 2 -32,768 to 32767 2 vbInteger
Long 4 -2,147,483,648 to 2,147,483,647 3 vbLong
Single 4 -3.402823E38 to 1.401298E45 4 vbSingle
Double (negative) 8 -1.79769313486232E308 to -4.94065645841247E-324 5 vbDouble
Double (positive) 8 4.94065645841247E-324 to 1.79769313486232E308 5 vbDouble
Currency 8 -922,337,203,685,477.5808 to 922,337,203,685,477.5807 6 vbCurrency
Date 8 1/1/100 to 12/31/9999 7 vbDate
String 1 per character Varies according to the number of characters 8 vbString
Object 4 Any defined object 9 vbObject
Variant Varies Any data type 12 vbVariant
Used defined Varies Varies 36 vbUserDefinedType
Although, there are some Const values that do not strictly correspond to data types,  mainly related to functions (IsArray, IsEmpty, IsError, IsNull, IsArray), or near to databases (DataObject):
Constant VBA7 Value
vbArray 8192
vbDataObject 13
vbDecimal           Decimal 14
vbEmpty 0
vbError 10
vbLongLong LongPtr 20 (only on implementations that support a LongLong value type)
vbNull 1

Leave a Reply

Your email address will not be published. Required fields are marked *