VBA-Excel: Fill Excel Range Values in a 2D Array

You can fill a range values from an excel work book into a two dimensional array. All you have to do is assign range values to a variable and then that variable will become array

Two Dimensional Dynamic array -1
Two Dimensional Dynamic array -1

Function FnFillValues()

    arrTwoD2 = Sheet9.Range(“A1: B5”)   

MsgBox “The value is B5 is ” & arrTwoD2(3, 2)

End Function

Two Dimensional Array -2
Two Dimensional Array -2

1 thought on “VBA-Excel: Fill Excel Range Values in a 2D Array”

  1. I have text data in excel worksheet in the cells B6:H14.
    Some rows will have 2 cells with contents while others have 4 and some will have 7. How do I copy these to a 2 dimensional array? I know the dimensions already and so, I am ok with the dimensions not being declared dynamic code.
    Do I need to use a loop (which I am currently planning to use)?
    Or is there an easier / more elegant way?


Leave a Comment