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

Array Example:

Let us see an example of basic one dimensional array.

Sub VBA_Basic_Array()
'Variable declaration
Dim arrayName(1) String
Public arrayName(1) String
Private arrayName(1) String

'Assign values to array variables
arrayName(1) )=“TestString1”

End Sub

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.

Please find the following link for types of arrays(Static & Dynamic).

Read More about Types of Arrays

Read More about Arrays

Read More about VBA Tutorial

Leave a Reply