title: Populate a two dimensional array with a single loop
body: <p>I have tried below code to fill a two dimensional array in Excel VBA and I was able to get the desired results. I would like to know if there is a better way of doing this or if you foresee any technical issue once I have a significantly large size of data in real case situations. Any ideas or suggestions would be appreciated for improvement.</p>
  
  <pre><code>Sub test_selection()
  ' My below array is based on values contained within
  ' selected cells
  ' The purpose of using two dimensional array is to 
  ' keep values in one column of array 
  ' while retaining cell addresses in 2nd 
  ' dimension to print some info in relevant cells
  ' offset to the selected cells
  
  Dim anArray() As String
  
  firstRow = Selection.Range("A1").Row
  LastRow = Selection.Rows(Selection.Rows.Count).Row
  colum = Selection.Columns.Column
  arrSize = LastRow - firstRow
  
  ReDim anArray(0 To arrSize, 1)
  cnt = 0
  
  For i = firstRow To LastRow
      anArray(cnt, 0) = CStr(Cells(i, colum).Value2)
      anArray(cnt, 1) = Cells(i, colum).Address
      cnt = cnt + 1
  Next i
  
  Call TestGetFileList(anArray)
  
  End Sub
  </code></pre>