vba - Excel VBA - 如何在 Do Until...循环中跳到下一次迭代

标签 vba excel

我试图使用“继续”语句跳到 vba 代码中的下一个迭代。它不起作用..

  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

有什么想法吗? 谢谢..

最佳答案

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)) 或否则你将陷入无限循环。

关于vba - Excel VBA - 如何在 Do Until...循环中跳到下一次迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39867524/

相关文章:

mysql - 对不同单元的多个 MySQL 查询

上个月第一天的Excel公式

Excel UDF 对具有特定背景颜色的单元格求和

excel - 按条件自动筛选,如果特定列中没有数据,应停止继续执行其中一项条件

javascript - 将 JSON 日期/日期(1388624400000)/转换为 Excel 中的日期

excel - 通过添加一些字符串来命名工作簿时出现语句结束错误

excel - 在单元格更改不更新时执行 excel VBA 宏

excel - 如何在 Excel VBA 中检查字符串是否为有效的 HHMMSS 值?

java - 使用 POI 读取一系列 Excel 工作表数据

VBA子例程填充公式向下列