Table of contents
Collapse the table of content
Expand the table of content

VarType Function

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Returns an Integer indicating the subtype of avariable. SyntaxVarType(varname) The required varnameargument is aVariant containing any variable except a variable of auser-defined type. Return Values

vbEmpty0Empty (uninitialized)
vbNull1Null (no valid data)
vbLong3Long integer
vbSingle4Single-precision floating-point number
vbDouble5Double-precision floating-point number
vbCurrency6Currency value
vbDate7Date value
vbError10Error value
vbBoolean11Boolean value
vbVariant12Variant (used only witharrays of variants)
vbDataObject13A data access object
vbDecimal14Decimal value
vbByte17Byte value
vbLongLong20LongLong integer (Valid on 64-bit platforms only.)
vbUserDefinedType36Variants that contain user-defined types

Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.

Remarks The VarType function never returns the value for vbArray by itself. It is always added to some other value to indicate an array of a particular type. The constant vbVariant is only returned in conjunction with vbArray to indicate that the argument to the VarType function is an array of type Variant. For example, the value returned for an array of integers is calculated as vbInteger + vbArray, or 8194. If an object has a defaultproperty, VarType(object) returns the type of the object's default property.


This example uses the VarType function to determine the subtype of a variable.

Dim IntVar, StrVar, DateVar, MyCheck
' Initialize variables.
IntVar = 459: StrVar = "Hello World": DateVar = #2/12/69# 
MyCheck = VarType(IntVar)    ' Returns 2.
MyCheck = VarType(DateVar)    ' Returns 7.
MyCheck = VarType(StrVar)    ' Returns 8.
© 2017 Microsoft