What is an Array?
An array is nothing but a group of values or elements of same data type store in a memory. All the grouped elements can have a common name. An array variable also called as an element. We can refer stored values from an array using array name or the array index number. An array elements are sequentially indexed.
Each variable in an array has a unique identifying index number. Index number also called as subscript. We make changes to variable using Index number. When we make changes to any variable in an array, it doesn’t affect other variables.
Here is the syntax of an array.
Dim VariableName(ArrayDimension/Subscript) DataType
Note: Variable Name also called as an element. Subscript is a unique identifying index number.
Let us see an example of basic one dimensional array.
Sub VBA_Basic_Array() 'Variable declaration Dim arrayName(1) String 'or Public arrayName(1) String 'or Private arrayName(1) String 'Assign values to array variables arrayName(0)=“TestString1” arrayName(1) )=“TestString1” End Sub
Note: In the above example 0 and 1 are unique identifying index number.
There are different usages with an array.
- It is used to store lists of data items of same data type.
- All array elements can be viewed in the Watch window.
- It is easy to maintain and sort data in an array.
- It has better performance.
- An array contains an unique identifying number.
Click on the following links of the useful resources. These helps to learn and gain more knowledge.