Excel VBA中的if-else循环中是否存在if-else循环?
在else语句中创建循环的其他方法是什么?在第一个Excel VBA中的if-else循环中是否存在if-else循环?,excel,vba,Excel,Vba,在else语句中创建循环的其他方法是什么?在第一个else和第二个If语句之间需要有End If。由于有两个“If”语句,所以在“Next”语句之前需要第二个“End If”。Next x,y是语法错误(你需要2个关闭Next),如果上面一行,它缺少结尾。另外Dim x,y,count,i,mhr,z,allowed,leftover As Integer没有做你想做的事。leftover是唯一被设置为整数的变量,所有其他变量都是变体 Sub lol_function() Dim x, y,
else
和第二个If
语句之间需要有End If
。由于有两个“If”语句,所以在“Next”语句之前需要第二个“End If”。Next x,y
是语法错误(你需要2个关闭Next
),如果上面一行,它缺少结尾。另外Dim x,y,count,i,mhr,z,allowed,leftover As Integer
没有做你想做的事。leftover
是唯一被设置为整数的变量,所有其他变量都是变体
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 condition
....
else
....
if condition
.....
else
.....
end if