What is VBA ARRAY Function
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.
how to use it
To use VBA's ARRAY function you need to understand its syntax and arguments:
- Arglist: The list of value with which you want to create an array [These values should be separated by commas (,)].
Examples to use ARRAY Function in VBA
To practically understand how to use VBA ARRAY function, you need to go through the below example where we have written a vba code by using it:
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
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.
Below are some important points which you need to take care while using ARRAY function in VBA.
- If there is no argument specified then it will return no array in the result.
About the Author
Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.