Sub lol_function()
Dim x, y, count, i, mhr, z, allowed, leftover As Integer
For y = 13 To 210
For x = 6 To 1000 Step 8
allowed = 50 * Cells(x, 8)
mhr = Cells(x, 7)
count = count + mhr
If mhr <= allowed And count <= allowed Then
Cells(x, y).value = mhr
Else
Cells(x, y).value = allowed + mhr - count
y = y + 1
leftover = count - allowed
If leftover <= allowed Then
Cells(x, y).value = leftover
count = leftover
Else
Cells(x, y).value = allowed
leftover = mhr - allowed
y = y + 1
End If
Next x, y
End Sub
如果我没有使用第二个If else循环,那么代码运行得很好,但是使用第二个if else语句,我总是得到"Next without For“错误。任何帮助都将不胜感激。
此外,如果我包括第二个结束,如果它弄乱了我的代码。我需要它成为
if condition
....
else
....
if condition
.....
else
.....
end if
有没有其他方法可以在else语句中创建循环?
发布于 2019-02-08 22:19:12
由于您有两个"If“语句,因此在"Next”语句之前需要第二个"End If“语句。
发布于 2019-02-08 22:18:37
您需要在第一个Else
语句和第二个If
语句之间使用End If
。
https://stackoverflow.com/questions/54600964
复制相似问题