Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Arrays – Two Dimensional, Static Array

Two dimensional array works like Mxn matrix.

Two Dimensional Array -1
Two Dimensional Array -1

For creating two dimensional static array, follow the below steps

  • Declare an two dimensional Array
  • Store values in array
  • Retrieve values from array.


Declare an two dimensional Array

Dim arrTwoD(1 To 3, 1 To 3)

Store values in array

arrTwoD(2, 3) = 6

Retrieve values from array.

Msgbox        arrTwoD(2, 3)

Complete Code:

Function FnTwoDimensionalArray()

   Dim arrTwoD(1 To 3, 1 To 3)    

   intCounter = 1

   For i = 1 To 3

      For j = 1 To 3

 arrTwoD(i, j) = intCounter

          intCounter = intCounter + 1

      Next

   Next

MsgBox "The Value in 2nd Row and 3rd Column is " & arrTwoD(2, 3)

End Function
Two Dimensional Array -2
Two Dimensional Array -2



Also Read:

  1. VBA-Excel: Date-Time Functions – TimeSerial() and TimeValue()
  2. VBA-Excel: Delete Blank Rows from Excel Work Sheet
  3. VBA-Excel: Date-Time Functions – Date(), Now() and Time()
  4. VBA-Excel: Get all the WeekDays or Working days in Specified Date Range, (excluding Satudays and Sundays)
  5. VBA-Excel: Arrays – Multi Dimensional Array