Returns an Integer indicating the subtype of a variable.

Syntax

VarType ( varname )

The required varnameargument is a Variant containing any variable except a variable of a user defined type.

Return Values

Constant

Value

Description

vbEmpty

0

Empty (uninitialized)

vbNull

1

Null (no valid data)

vbInteger

2

Integer

vbLong

3

Long integer

vbSingle

4

Single-precision floating-point number

vbDouble

5

Double-precision floating-point number

vbCurrency

6

Currency value

vbDate

7

Date value

vbString

8

String

vbObject

9

Object

vbError

10

Error value

vbBoolean

11

Boolean value

vbVariant

12

Variant (used only with arrays of variants)

vbDataObject

13

A data access object

vbDecimal

14

Decimal value

vbByte

17

Byte value

vbUserDefinedType

36

Variants that contain user-defined types

vbArray

8192

Array

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 default property, VarType(object) returns the type of the object's default property.

Example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

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

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

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.