The VBA IsArray Function

Description

The VBA IsArray function returns a Boolean, indicating whether a supplied variable is an Array or not.

The syntax of the function is:

IsArray( VarName )

Where the VarName argument is the variable that you want to test.


VBA IsArray Function Examples

Example 1

' Test if three different variables are Arrays.
Dim i As Integer
Dim iVals() As Integer
Dim names( 5 ) As String
Dim isArr1 As Boolean
Dim isArr2 As Boolean
Dim isArr3 As Boolean
isArr1 = IsArray( i )
isArr2 = IsArray( iVals )
isArr3 = IsArray( names )
' Now, isArr1 = False, isArr2 = True and isArr3 = True.

In the above example:


Example 2

' Test if a Variant is an array (before and after an array is assigned to it).
Dim isArr1 As Boolean
Dim isArr2 As Boolean
Dim vals As Variant
isArr1 = IsArray( vals )
' isArr1 is now equal to False.
vals = Array( 1, 2, 3, 4, 5 )
isArr2 = IsArray( vals )
' isArr2 is now equal to True.

In the above example, the variable vals is initially declared as a Variant and so, when testing if this is an Array, the isArray function returns the value False.

However, after an Array has been assigned to vals, the isArray function recognises that this and returns the value True.