title: VBA for loop ending early
body: <p>If I'm iterating k = 1 to 100, I need to sometimes restart an iteration if a criteria isn't met. In this case, I'm creating a random number between 1 and 100, but if that number is below 51, I want the iteration to start over.</p>
  
  <p>Right now the code is returning a variable number of values. Sometimes 1, sometimes 90. </p>
  
  <p>Any ideas why?</p>
  
  <pre><code>Public k as long
  Sub Example()
  
  For k = 1 To 100
      Call ExampleExtended
  Next k
  
  End Sub
  
  
  Sub ExampleExtended()
  Dim Val As Integer
  
  Val = Int((100 - 1 + 1) * Rnd)
  
  If Val &lt; 51 Then
      k = k - 1
      Exit Sub
  End If
  
  Debug.Print Val
  
  End Sub
  </code></pre>