Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Option Explicit
Sub main()
Dim counter As Integer
counter = 1
Do While counter < 50
Debug.Print ("ExitでDoループ終了")
Exit Do
counter = counter + 1
Loop
For counter = 0 To 50 Step 1
Debug.Print ("ExitでForループ終了")
Exit For
Next counter
Call exitTest
Debug.Print ("ExitでSub終了")
Exit Sub
Debug.Print ("ここは表示されません")
'実行後、イミディエイト ウインドウに
'以下の出力があります
'
'ExitでDoループ終了
'ExitでForループ終了
'ExitでFunction終了
'ExitでSub終了
End Sub
Function exitmain()
Debug.Print ("ExitでFunction終了")
Exit Function
Debug.Print ("ここは表示されません")
End Function
このサイトはリンクフリーです。リンクを貼る際に連絡は不要です。
© EXCEL VBA リファレンス all rights reserved.