title: How to reverse a For loop
body: <p>I have a problem with my macro. It deletes row that fullfil certain criteria. But when few consecutive rows fullfil those criteria an error occurs. When the row is deleted the other rows are shifted up so if i.e. row(2:2) and row(3:3) fullfil the criteria then the row(2:2) is deleted and row(3:3) is shifted up, so it becomes row(2:2), and For loop goes to another row (third one). As a result row that used to be row(3:3) and now is row(2:2) is omitted and not deleted.<br>
  In order to deal with this topic I think that it is enough to reverse to For loop, so it wouldn't go from up to bottom but from bottom to top. Te resulat would be double checking of some rows, but no rows would be omitted.<br>
  The proble is that I don't know how to revese the For loop. I have tried to change 'For x = startrow To endrow' to 'For x = endrow To startrow', but it didn't help.<br>
  Here is the code:</p>
  
  <pre><code>Sub Repurchase_upload()
  
  Dim Worksheet As Worksheets
  startrow = Worksheets("GUTS").Cells(10, 1)
  endrow = Worksheets("GUTS").Cells(11, 1)
  
   For x = startrow To endrow 'I have tried to change this line into: 'For x = endrow To startrow', but it didn' help
              If Cells(x, "A").Value &lt;&gt; "AA" And Cells(x, "A").Value &lt;&gt; "AB" And Cells(x, "A").Value &lt;&gt; "AC" And Cells(x, "A").Value &lt;&gt; "AD" And Cells(x, "A").Value &lt;&gt; "AE" And     Cells(x, "A").Value &lt;&gt; "AH" And Cells(x, "A").Value &lt;&gt; "AI" And Cells(x, "A").Value &lt;&gt; "AF" And Cells(x, "A").Value &lt;&gt; "AG" Then
              Cells(x, "A").EntireRow.Delete
  
              End If
  
  
  
      Next
  End Sub  
  </code></pre>
  
  <p>Thank you all a lot in advance,<br>
  with best regards,<br>
  Artur Rutkowski</p>