Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA中的if-else循环中是否存在if-else循环?_Excel_Vba - Fatal编程技术网

Excel VBA中的if-else循环中是否存在if-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语句中创建循环的其他方法是什么?

在第一个
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