You are on page 1of 2
ssoa017 VEAExitFor VBA - Exit For https://www.tutorialspoint.com/vba/vba_exit_for_statement.htm Copyright © tutorialspoint.com A Exit For statement is used when we want to exit the For Loop based on certain criteria, When Exit For is executed, the control jumps to the next statement immediately after the For Loop. Syntax Following is the syntax for Exit For Statement in VBA. Exit For Flow Diagram If False ray a Example The following example uses Exit For. If the value of the Counter reaches 4, the For Loop is exited and the control jumps to the next statement immediately after the For Loop. Private Sub Constant_demo_Click() Dim a As Integer a=ie For i = @ To a Step 2 ‘i is the counter variable and it is incremented by 2 MsgBox ("The value is i is : " & i) If i= 4 Then i= 4i* 10 ‘This is executed only if hiipsstonywulralspeinLeonvegi-binlrinpage.ca 12 ssoa017 VEAExitFor MsgBox ("The value is i is : " & i) Exit For 'Exited when ima End If Next End sub When the above code is executed, it prints the following output in a message Box. The value is i is : @ The value is 4 is : 2 The value is iis: 4 The value is i is : 40 hiipsstonywulralspeinLeonvegi-binlrinpage.ca

You might also like