BruceWayne
BruceWayne

Reputation: 23283

Step -1 skips the loop altogether

My For loop keeps skipping when I try to use the Step -1

Dim locRow as Integer, lastRow as Integer, i as Integer
locRow = 1
lastRow = 10

for i = (locRow + 1) to lastRow Step -1
    If IsEmpty(.Cells(i,1)) Then
        Rows(i).EntireRow.delete
    End if
Next i

When I get to the For line, it skips the loop part completely. If I remove Step -1, then it works, but I have to add i = i - 1 to my If() statement. That's okay I guess, but I'm curious as to why the step backwards won't work.

Thanks for any ideas!

Upvotes: 1

Views: 45

Answers (1)

Chrismas007
Chrismas007

Reputation: 6105

Per the comments:

Dim locRow as Integer, lastRow as Integer, i as Integer
locRow = 1
lastRow = 10

for i = lastRow to (locRow + 1) Step -1
    If IsEmpty(.Cells(i,1)) Then
        Rows(i).EntireRow.delete
    End if
Next i

Upvotes: 1

Related Questions