Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Arrays – Two Dimensional, Static Array

Two dimen­sional array works like Mxn matrix.

Two Dimensional Array -1

Two Dimen­sional Array –1

For cre­at­ing two dimen­sional sta­tic array, fol­low the below steps

  • Declare an two dimen­sional Array
  • Store val­ues in array
  • Retrieve val­ues from array.


Declare an two dimen­sional Array

Dim arrTwoD(1 To 3, 1 To 3)

Store val­ues in array

arrTwoD(2, 3) = 6

Retrieve val­ues from array.

Msg­box        arrTwoD(2, 3)

 

Com­plete 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 Dimen­sional Array –2

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: