首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Excel VBA -如何在Do Until...Loop中跳到下一次迭代

Excel VBA -如何在Do Until...Loop中跳到下一次迭代
EN

Stack Overflow用户
提问于 2016-10-05 15:08:57
回答 2查看 32.4K关注 0票数 6

我正在尝试跳到我的vba代码中的下一个迭代,使用'continue‘语句。它不工作了..

代码语言:javascript
复制
  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

有什么想法吗?谢谢..

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-05 15:52:02

VBA没有Continue语句。您可以通过执行以下操作来绕过它

代码语言:javascript
复制
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

代码语言:javascript
复制
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)),否则您将以无限循环结束。

票数 6
EN

Stack Overflow用户

发布于 2018-03-01 01:15:50

所以这是另一种对我有效的可能性。只需跳过不需要的行...

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39867524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档