title: "Subscript out of range" error when calling LBound() or UBound() on a VBA array
body: <p>The following code produces the error "Subscript out of range" and I do not know why. Can someone please explain?</p>
  
  <pre><code>    Dim errorc As Integer
      Dim myarray() As Variant
  
  
      errorc = 1
  
      If Len(Me.txt_Listnum) = 0 Then
      ReDim Preserve myarray(errorc)
      myarray(errorc) = "Numer Listy"
      errorc = errorc + 1
      End If
  
      If Len(Me.cbo_ByWho) = 0 Then
      ReDim Preserve myarray(errorc)
      myarray(errorc) = "Wystawione przez"
      errorc = errorc + 1
      End If
  
      If Len(Me.cbo_ForWho) = 0 Then
      ReDim Preserve myarray(errorc)
      myarray(errorc) = "Wystawione na"
      errorc = errorc + 1
      End If
  
      For i = LBound(myarray) To UBound(myarray)
          msg = msg &amp; myarray(i) &amp; vbNewLine
      Next i
  
      If errorc &gt; 0 Then
         MsgBox "da" &amp; msg
  
      End If
  </code></pre>