What is an array

What is an Array?

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.

Syntax of an Array:

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.

Array Example:

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.

Usage of an Array:

There are different usages with an array.

  1. It is used to store lists of data items of same data type.
  2. All array elements can be viewed in the Watch window.
  3. It is easy to maintain and sort data in an array.
  4. It has better performance.
  5. An array contains an unique identifying number.

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Arrays in Excel VBA Tutorial VBA Functions List Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply