120

私は、VBA の While...Wend ループを使用しています。

Dim count as Integer

While True
    count=count+1

    If count = 10 Then
        ''What should be the statement to break the While...Wend loop? 
        ''Break or Exit While not working
    EndIf
Wend

「While count<=10...Wend」のような条件は使いたくない

4

3 に答える 3

208

While/ループは、または外部ブロック ( /または別の終了可能なループ)から終了することによってWendのみ、時期尚早に終了できます。GOTOExit subfunction

Do代わりにループに変更します。

Do While True
    count = count + 1

    If count = 10 Then
        Exit Do
    End If
Loop

または、設定した回数ループする場合:

for count = 1 to 10
   msgbox count
next

Exit For途中で終了するために上記で使用できます)

于 2012-08-30T15:58:22.020 に答える