VBA Function: VarType

The VBA VarType function returns an integer value corresponding to the type of the variable passed as an argument.

Usage:

VarType(variable)


Return Values

The list of values returned by the VarType function:

ConstantValue
vbEmpty0
vbNull1
vbInteger2
vbLong3
vbSingle4
vbDouble5
vbCurrency6
vbDate7
vbString8
vbObject9
vbError10
vbBoolean11
vbVariant12
vbDataObject13
vbDecimal14
vbByte17
vbLongLong20
vbUserDefinedType36
vbArray8192
If the variable is an array, the number returned by the function will be the sum of two values. For example, a value of 8194 corresponds to 8192 (vbArray) + 2 (vbInteger).

Example of Usage

Using the VarType function to display the type of the variable:

Sub example()
    
    myVariable = "Excel"
    
    MsgBox VarType(myVariable) 'Returns: 8
    
End Sub

Using the VarType function to display the type of the array:

Sub example()
    
    myArray = Split("x l p", " ")
    
    MsgBox VarType(myArray) 'Returns: 8200
    
End Sub

The value 8200 here corresponds to 8192 (vbArray) + 8 (vbString).