Static Arrays

A static array has a fixed number of elements that is specified when the array is declared. You declare a static array using the following syntax:

Dim ArrayName(n) As type
					

ArrayName is the name of the array, which follows the same naming rule as regular VBA variables. n specifies the highest index in the array. type can be any of VBA's built in data types as well as UDT's. An example is

Dim MyArray(100) As Integer

This statement creates an array of integers. Because VBA's default is to start array indexes at 0, this array actually contains 101 elements, at indexes 0 through 100. Once an array exists, you access its elements using any expression to specify the index. For example, consider

 MyArray(0) = 12 x = 1 MyArray(x) = 15 ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.