title: Using Rows.Count to assign dimensions to a multi-dimensional array in VBA
body: <p>I'm struggling with this program I'm trying to write. In it, I need to use a two dimensional array that looks like array(# rows in table, 2). For some reason, even though I can get the number of rows correctly, I keep getting the Compile error: Constant expression required.</p>
  
  <p>If anybody could give me any help it'd be much appreciated. I can't just assign a static number to it because the table is always going to be increasing as time goes on, and I know you cannot resize an array once it's built.</p>
  
  <p>This is my code if it'll provide any help.</p>
  
  <pre><code>Sub arrayToTest()
  Dim rng As Range, row As Range, cell As Range, RowCount As Long, rowsinTable As Integer
  Set rng = Sheets("Sheet1").Range("TestTable")
  rowsinTable = rng.Rows.Count
  Dim arrayTest(rowsinTable, 2) As String
  RowCount = 1
  For Each row In rng.Rows
     arrayTest(RowCount - 1, 0) = rng.Cells(RowCount, 2)
     RowCount = RowCount + 1
  Next row
  End Sub
  </code></pre>
  
  <p>The test table I'm using has 3 rows.</p>