The VBA ARRAY function is listed under the array category of VBA functions. When you use it in a VBA code, it can store a set of values that you supplied. In simple words, it can store more than one value or a set of values specified by you and you can use it when you need to use that arrays in your code.
- Arglist: The list of value with which you want to create an array [These values should be separated by commas (,)].
To practically understand how to use the VBA ARRAY function, you need to go through the below example where we have written a VBA code by using it:
In the above code, we have defined one-dimensional arrays using the array function with three values starting at index 0 and in the same code, we have used Debug.Print to get all the value using in the immediate window using index numbers.
Sub example_ARRAY() Dim myArray As Variant myArray = Array(10, 20, 30) Debug.Print myArray(0) Debug.Print myArray(1) Debug.Print myArray(2) End Sub
- If there is no argument specified then it will return no array in the result.