Array Function in Excel VBA
The Array function in Excel VBA can be used to quickly and easily initialize an array. Place a command button on your worksheet and add the following code lines:
1. First, create a variable named departments of type Variant.
2. Use the Array Function to assign an array to the variable departments. Add the following code line:
3. To show the element with index 1, add the following code line:
Result:
By default, the element's index of the array starts from 0.
4. Add Option Base 1 to the General Declarations section if you want the index to start from 1.
Result when you click the command button again.
For a practical example of the Array function, see our example program Month Names.
If you're new here, welcome to Excel Easy! Join over 1 million monthly Excel learners. You can find popular courses here: Data Analysis in Excel and Excel VBA.