Arrays in Excel VBA



Arrays in Excel VBA in no different from Arrays in other Programming Languages. Arrays store different values under single variable name. The values are differentiated using Index. Irrespective of a programming language, an array has to be defined, populated with valid values and retrieved using a valid index number.

An array can be either one dimensional, two dimensional or three dimensional. A one dimensional array is one whose values are retrieved using a single valid index number. Two dimensional is addressed using two valid index number and three dimensional by three valid index numbers. 
  
Let’s see how to declare an array. First, a user-defined data type DETAIL is declared.


 



Excel sheet is populated as shown in the figure.



Following piece of code is appended between sub Workbook_open & end sub.Student_Data is array variable of type DETAIL. Its size is 10. 



On execution, we get the following output.