2012-08-30 11 views
79

VBAのWhile ... Wendループを使用しています。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 

私は `のような条件を使用したくない< = 10 ... Wendの

答えて

141

をカウントしながらWhile/WendのみGOTOまたはExit sub(外側のブロックから出てくることで、早期に終了することができます/ function/another exitable loop

Do loop inteadに変更してください。

Do While True 
    count = count + 1 

    If count = 10 Then 
     Exit Do 
    End If 
Loop 

(または制御変数をインクリメントセットとループ用)

for count = 1 to 10 
    msgbox count 
next