# End
{: .no_toc }

Ends a procedure or block.

Syntax:

- **End**  
  Terminates execution immediately. Never required by itself but may be placed anywhere in a procedure to end code execution, close files opened with the [**Open**](/tB/Core/Open.md) statement, and to clear variables.

- **End Function**  
  Required to end a [**Function**](/tB/Core/Function.md) statement.
  
- **End If**  
  Required to end a block [**If...Then...Else**](/tB/Core/If-Then-Else.md) statement.
  
- **End Property**  
  Required to end a [**Property Get**](/tB/Core/Property.md), [**Property Let**](/tB/Core/Property.md), and [**Property Set**](/tB/Core/Property.md) procedure.
  
- **End Select**  
  Required to end a [**Select Case**](/tB/Core/Select-Case.md) statement.

- **End Sub**
  Required to end a [**Sub**](/tB/Core/Sub.md) statement.

- **End Type**
  Required to end a user-defined type (UDT) definition ([**Type**](/tB/Core/Type.md) statement).

- **End With**
  Required to end a [**With**](/tB/Core/With.md) statement.

When executed, the **End** statement resets all module-level variables and all static local variables in all modules. To preserve the value of these variables, use the [**Stop**](/tB/Core/Stop.md) statement instead --- execution can then resume while preserving the value of those variables.

> [!IMPORTANT]
>
> The **End** statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened by using the **Open** statement are closed, and memory used by the program is freed. Object references held by other programs are invalidated.

The **End** statement provides a way to force the program to halt. For normal termination of a Visual Basic program, all forms should be unloaded. The program closes as soon as there are no other programs holding references to objects created from public class modules and no code executing.

### Example

This example uses the **End** statement to end code execution if the user enters an invalid password.

```tb check_build
Sub Form_Load() 
  Dim Password, Pword 
  PassWord = "Swordfish" 
  Pword = InputBox("Type in your password") 
  If Pword <> PassWord Then 
    MsgBox "Sorry, incorrect password" 
    End
  End If
End Sub
```