Declaring arrays
Arrays are variables of a specific type. While a variable can store only one value at a time, arrays store multiple values, or elements. An array is therefore a group of variables sharing a common name. One example of an array would be the days of the week typed in a single column in Excel.
Like variables, arrays are also declared with a Dim
statement. The rest of the line of code differs in the sense that with arrays, you have to specify the number of elements in the array.
In its simplest form, the elements consist of a first and last index number, separated with the To
keyword, all in parentheses. This is known as a one-dimensional array, which stores a single line of values. Multidimensional arrays stores multiple rows and columns of values.
In this recipe, we will be discussing three types of arrays:
- One-dimensional arrays
- Multidimensional arrays
- Dynamic arrays
Getting ready
Open Excel and make sure that Book1 is active. Save...