VarType function

Category: Array / Information

Summary

Subtype of a variable.

Syntax

VarType(varname) The required varname argument is a Variant containing any variable except a variable of a user-defined type.

Example

Example
This example uses the VarType function to determine the subtypes of different variables, and in one case, the type of an object's default property.
Dim MyCheck
Dim IntVar, StrVar, DateVar, AppVar, ArrayVar
' Initialize variables.
IntVar = 459: StrVar = "Hello World": DateVar = #2/12/1969#
Set AppVar = Excel.Application
ArrayVar = Array("1st Element", "2nd Element")
' Run VarType function on different types.
MyCheck = VarType(IntVar) ' Returns 2.
MyCheck = VarType(DateVar) ' Returns 7.
MyCheck = VarType(StrVar) ' Returns 8.
MyCheck = VarType(AppVar) ' Returns 8 (vbString)
' even though AppVar is an object.
MyCheck = VarType(ArrayVar) ' Returns 8204 which is
' `8192 + 12`, the computation of
' `vbArray + vbVariant`.

Microsoft Support Page

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/vartype-function

Back to Functions