Once a userform is displayed using the Show method it remains displayed until it is dismissed, using the Unload statement or it is hidden using the Hide method.
Never Hide your userforms always close them since hiding them will not release the resources.
To close a userform use the Unload statement.

Call UnLoad(frmDisplay) 

When the userform is displayed it remains visible until it is dismissed
When a userform is unloaded its controls are reset to their original values.
If the user's choice must be used later on you need to store the value in a global variable.

A userform is automatically unloaded by default when the user clicks the close button (cross) in the upper right corner.
This close button has no event of its own.
Clicking the close button will stop execution of the userform and any cleanup instructions will not be executed.
The solution is to place your cleanup instructions inside the Userform_Terminate event handler.
This way both the Cancel and the close button will run the cleanup process.

Private SubUserForm_Terminate() 
End Sub

If for some reason you would like your userform to disappear immediately while its macro is still executing, use the Hide method at the top of the procedure and follow it with a DoEvents command.
For example the following procedure, the Userform disappears immediately when the button is pressed and then the userform eventually unloads once the code has been executed.

Private Sub CommandButton1_Click() 
   For r = 1 to 10000
''do something
   Next r
   Unload Me
End Sub

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext