我正在尝试跳到我的vba代码中的下一个迭代,使用'continue‘语句。它不工作了..
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有什么想法吗?谢谢..
发布于 2016-10-05 15:52:02
VBA没有Continue语句。您可以通过执行以下操作来绕过它
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或
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注意:在两个版本中,我都将IsEmpty(xlSheet.Cells(row, 1))更改为IsEmpty(xlSheet.Cells(row + 1, 1)),否则您将以无限循环结束。
发布于 2018-03-01 01:15:50
所以这是另一种对我有效的可能性。只需跳过不需要的行...
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
Loophttps://stackoverflow.com/questions/39867524
复制相似问题