Using Variables And Arrays

When you specify the size of an array, you indicate the upper and lower bounds of the array, or the first and last index value. In the example, Dim NewArray(1 To 45), the statement creates an array with 45 elements with the lower bound of the array of 1 and the upper bound of 45. If desired, you can omit the lower bound value when you declare an array, as in the example Dim NewArray(4 5). When you do not specify the lower bound of the array, VBA assigns a lower bound value of 0. Therefore, the specified array, NewArray, actually has 46 elements starting with the first element at 0 and the final element at 45.

If you want to give all the arrays you declare a lower bound value of 1, you do so by placing the following statement before any procedures in your module: Option Base l.With this statement, you only have to specify the upper bound of the array. You can specify any number as the lower bounds for the arrays within the module. Keep the lower bounds in mind when declaring the array.

□ Use the Cells property to assign the values of the array to cells in the spreadsheet.

Note: For more information on the Cells property see Chapter 11.

0 Switch to Excel and run the macro.

■ Excel places the values in the array in the specified cells.

0 0

Post a comment