title: Ignore "subscript out of range" error once, to deal with first iteration
body: <p>I am making a loop that calculates the trajectory of a projectile and want the loop to stop when the projectile is at the same height as the target AND the projectile is on the decent. This is ensured by the Do Until... line. However, when the loop starts y(i-2) does not exist [y(-1)], resulting in a "runtime error '9' - subscript out of range". Using "On Error Resume Next" does allow the loop to continue but I often make mistakes and certainly will when adding more things to the loop (e.g. moving target, yaw, wind, etc.). For this reason I would like vba to ignore the runtime error only once and break on any following errors.</p>
  
  <p>The relevant section of code is as follows:</p>
  
  <pre><code>vx(0) = V * Cos(Theta)  'set the initial conditions
  vy(0) = V * Sin(Theta)
  vz(0) = 0
  x(0) = 0
  y(0) = 0
  z(0) = 0
  i = 1
  t = 0
  
  On Error Resume Next
  Do Until y(i - 1) &lt; TargetAlt And y(i - 1) &lt; y(i - 2)   'Stop when the projectile is at the same height
                                                                                   'as the target AND the projectile in on the
                                                                                   'decent of its trajectory
  
      'If the projectile is moving up then drag and gravity are working together
      'If not drag is working against gravity.
      If vy(i - 1) &gt; 0 Then
              vy(i) = vy(i - 1) + h * (-g - (DragCof * (vy(i - 1) ^ 2)))
      Else: vy(i) = vy(i - 1) + h * (-g + (DragCof * (vy(i - 1) ^ 2)))
      End If
  
      'The y position of the projectile
      y(i) = y(i - 1) + h * (vy(i - 1))
  
      'x direction velocity
      vx(i) = vx(i - 1) + h * (-DragCof * (vx(i - 1) ^ 2))
      'The x position of the projectile
      x(i) = x(i - 1) + h * (vx(i - 1))
  
      'z direction velocity
      'The z position of the projectile
  
      'parameters
      t = t + h
      i = i + 1
  
  Loop
  </code></pre>
  
  <p>Starting the loop at i = 2 and adjusting the initial conditions accordingly would potentially work however I would like to avoid this if possible.</p>