An Excel VBA array is a group of variables. You can refer to a specific variable (element) of an array by using the array name and the index number. To create a one-dimensional array, execute the following steps.
Place a command button on your worksheet and add the following code lines:
Films(1) = "Lord of the Rings"
Films(2) = "Speed"
Films(3) = "Star Wars"
Films(4) = "The Godfather"
Films(5) = "Pulp Fiction"
1. The first code line declares a String array with name Films. The array consists of five elements.
2. Next, we initialize each element of the array. In other words: we assign beginning values.
3. Finally, we display the fourth film using a MsgBox.
Exit the Visual Basic Editor and test the array.
Result when you click the command button on the sheet:
Did you find this information helpful? Show your appreciation, vote for us.