[英]Excel VBA - how to skip to next iteration in a Do Until...Loop
I'm trying to skip to the next iteration in my vba code, with the 'continue' statement.我正在尝试使用“继续”语句跳到我的 vba 代码中的下一次迭代。 Its not working..
它不工作..
Do Until IsEmpty(xlSheet.Cells(row, 1))
row = row + 1
If xlSheet.Cells(row, 2) = "Epic" Then
Continue
End If
xlSheet.Cells(row, 1).Value = 5
Loop
Any idea??任何的想法?? Thanks..
谢谢..
VBA does not have a Continue
statement. VBA 没有
Continue
语句。 You can get around it by doing something like你可以通过做类似的事情来解决它
Do Until IsEmpty(xlSheet.Cells(row + 1, 1))
row = row + 1
If xlSheet.Cells(row, 2) <> "Epic" Then
xlSheet.Cells(row, 1).Value = 5
End If
Loop
or或者
Do Until IsEmpty(xlSheet.Cells(row + 1, 1))
row = row + 1
If xlSheet.Cells(row, 2) = "Epic" Then
GoTo ContinueDo
End If
xlSheet.Cells(row, 1).Value = 5
ContinueDo:
Loop
Note: In both versions I changed IsEmpty(xlSheet.Cells(row, 1))
to IsEmpty(xlSheet.Cells(row + 1, 1))
or else you will end up with an infinite loop.注意:在这两个版本中,我都将
IsEmpty(xlSheet.Cells(row, 1))
更改为IsEmpty(xlSheet.Cells(row + 1, 1))
否则您将最终IsEmpty(xlSheet.Cells(row + 1, 1))
无限循环。
So this is another possibility that works for me.所以这是另一种对我有用的可能性。 Just skip the unwanted lines...
只需跳过不需要的行...
Do Until IsEmpty(xlSheet.Cells(row, 1))
row = row + 1
Do while xlSheet.Cells(row, 2) = "Epic"
row = row + 1
Loop
xlSheet.Cells(row, 1).Value = 5
Loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.