title: Dynamically appending an array in VBA
body: <p>I want to append an array with a number depending on the condition of various variables. Here is the code I've come up with: I begin with an empty array.</p>
  
  <pre><code>Sub makeArr()
  Dim myArr() As Integer
  If box1 = True Then
      ReDim Preserve myArr(LBound(myArr) To UBound(myArr) + 1)
      myArr(UBound(myArr)) = 1
  End If
  
  If box2 = True Then
      ReDim Preserve myArr(LBound(myArr) To UBound(myArr) + 1)
      myArr(UBound(myArr)) = 2
  End If
  End Sub
  </code></pre>
  
  <p>Obviously this is an example so not the most elegant way of putting it but it doesn't work as I can't seem to reDim the array as it doesn't initially have a <code>ubound</code> or an <code>lbound</code>. When I dim it as <code>myArr(0 to 0)</code> this also fails.</p>
  
  <p>Any ideas?</p>