The VBA Array Function

Description

The VBA Array function creates an array containing a supplied set of values.

The syntax of the function is:

Array( Arglist )

Where the Arglist argument is the list of values that you want to make up the array. These values should be separated by commas.


VBA Array Function Example

The following VBA code creates an array of three Integer values.

' Create an array containing three Integer values.
Dim array1 As Variant
array1 = Array( 5, 8, 2 )
' The array "array1" now has length 3, and contains the values 5, 8 and 2.

The above call to the VBA Array function returns a one-dimensional array, starting at index 0. The new array has the following elements:

array1(0) = 5
array1(1) = 8
array1(2) = 2

For further details on creating and using arrays in VBA, see the Visual Basic Arrays page.