我正在遍历表格的行,如果不满足某些条件则删除行。但奇怪的是,即使完成了循环,我的for循环也从未退出。我做错了什么?
lastr = Range("a2").End(xlDown).Row
For r = 2 To lastr
If Cells(r, 1).Value <> "SHORT POSITIONS" And Cells(r, 7).Value = 0 And Cells(r, 10).Value <> "Yes" Then
Rows(r).Delete
r = r - 1
lastr = lastr - 1
End If
Next r
For r = lastr to 2 step -1
。这样,您就不必担心r = r-1
和lastr = lastr -1
。请注意,翻译中的句子顺序可能与原文略有不同,但意思保持一致。 - Vincent G