【发布时间】:2017-11-21 05:44:24
【问题描述】:
我在 Excel VBA 上的代码有问题。我正在尝试编写一个嵌套循环。但我不断收到编译错误: Next without For ( the line with Next r)
这是我的代码
Sub clear()
r = 2
i = 310
For c = 15 To 28
r = 2
i = 310
For r = 2 To 306
If Cells(r, c) > Cells(306, c) Then
If Cells(r, 4) <> Cells(i - 1, c) Then
[ Cells(i, c) = Cells(r, 4) i = i + 1]
r = r + 1
Next r
Cells(308, c) = i - 309
Next c
End Sub
提前致谢
【问题讨论】:
-
尝试缩进你的代码,你可能会发现你有 2 x
Ifs 没有End If,这可能是原因。此外,在您共享的代码中,您没有对变量I执行任何操作,您可以将I替换为 310(或在顶部声明为Const) -
感谢@ShaiRado,我添加了 End if 并且它有效
标签: excel for-loop compiler-errors nested vba