步骤-1完全跳过循环

时间:2015-08-14 19:23:02

标签: excel vba excel-vba for-loop

当我尝试使用For

时,我的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

当我到达For行时,它会完全跳过循环部分。如果我删除了Step -1,那么它可以正常运行,但我必须将i = i - 1添加到我的If()语句中。我觉得这没关系,但我很好奇为什么退步不起作用。

感谢您的任何想法!

1 个答案:

答案 0 :(得分:1)

根据评论:

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