title: Using an if statement within a for loop- Excel VBA
body: <p>I'm having trouble using an if statement inside a for loop in excel vba. The output of the debugger is not what I expect. I can post the full code of what I am trying to accomplish, but I think I have narrowed it down to what I don't understand. Here is my code:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  Dim i As Integer
  
  For i = 9 To 60 Step 3
  
  If Cells(i, "DR").Value &lt; Cells(i, "EB").Value Then
      Debug.Print i &amp; "-ifloopstart"
      Cells(i, "DR").Value = 999999
      Debug.Print i &amp; "-ifloopend"
  End If
  
  Next i
  
  End Sub
  </code></pre>
  
  <p>The output of the debugger is:</p>
  
  <pre><code>9-ifloopstart
  33-ifloopstart
  51-ifloopstart
  51-ifloopend
  33-ifloopend
  9-ifloopend
  </code></pre>
  
  <p>However, I expected:</p>
  
  <pre><code>9-ifloopstart
  9-ifloopend
  33-ifloopstart
  33-ifloopend
  51-ifloopstart
  51-ifloopend
  </code></pre>
  
  <p>Can someone explain how this works? It seems to be looping back to the beginning of the if statement instead of finishing the if statement. How can I modify the code to get the output I expect? I've been struggling with this for hours and it seems so simple :( . </p>