跳到循环vba中的下一个迭代 [英] Skip to next iteration in loop vba

查看:516
本文介绍了跳到循环vba中的下一个迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的条件循环,如果条件为真,它将进​​入下一次迭代.到目前为止,我的代码是:

I am trying to create a simple conditional loop that will go to the next iteration if a condition is true. The code I have so far is:

For i = 2 To 24
    Level = Cells(i, 4)
    Return = Cells(i, 5)

    If Return = 0 And Level = 0 Then
        'Go to the next iteration
    Else
    End If
Next

我尝试了GoTo NextIteration,但这出现了错误未定义标签".这可能有一个非常简单的解决方案,但是非常感谢您的协助. 谢谢.

I have tried GoTo NextIteration, but this comes up with the error 'Label not defined'. This probably has a very simple solution, but assistance would be much appreciated. Thanks.

推荐答案

For i = 2 To 24
  Level = Cells(i, 4)
  Return = Cells(i, 5)

  If Return = 0 And Level = 0 Then GoTo NextIteration
  'Go to the next iteration
  Else
  End If
  ' This is how you make a line label in VBA - Do not use keyword or
  ' integer and end it in colon
  NextIteration:
Next

这篇关于跳到循环vba中的下一个迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆