Description
Ends a procedure or block.
Syntax
End
End Function
End If
End Property
End Select
End Sub
End Type
End With
The End statement syntax has these forms:
Statement |
Description |
End |
Terminates procedure execution. Never required by itself but may be placed anywhere in a procedure to close files opened with the Open statement and to clear variables. |
End Function |
Required to end a Function statement. |
End If |
Required to end a block If...Then...Else statement. |
End Property |
Required to end a Property Let, Property Get, or Property Set procedure. |
End Select |
Required to end a Select Case statement. |
End Sub |
Required to end a Sub statement. |
End Type |
Required to end a user-defined type definition (Type statement). |
End With |
Required to end a With statement. |
Remarks
Note
When executed, the End statement resets all module-level variables and all static local variables in all modules. If you need to preserve the value of these variables, use Stop instead. You can then resume execution while preserving the value of those variables.
See Also
Exit Statement, Function Statement, If...Then...Else Statement, Property Get Statement, Property Let Statement, Property Set Statement, Select Case Statement, Stop Statement, Sub Statement, Type Statement, With Statement.
Example
This example uses the End Statement to end code execution, a Select Case block, and a Sub procedure.
Sub EndStatementDemo() For Number = 1 To 2 ' Loop 2 times. Select Case Number ' Evaluate Number. Case 1 ' If Number equals 1. Debug.Print Number ' Print value to Debug window. Case Else ' If Number does not equal 1. End ' Terminate procedure execution. End Select ' End of Select Case Statement. Next Number End Sub ' End of Sub procedure.