thebiglebowski11
thebiglebowski11

Reputation: 1461

excel vba unloading contents from a form

I have a userform that is opened when a user clicks a button in a worksheet. After clicking the button, if the user inputs some data, then decides to close the form, the previously entered data remains in the form. How can (in code) I get rid of that data so it opens with the default every time the button is clicked?

Currently I just use

form.Show

when the button is clicked and

form.Hide

when the user hits the cancel button within the form.

Thanks!

Upvotes: 0

Views: 1752

Answers (2)

Charlie Strawn
Charlie Strawn

Reputation: 387

You could catch the closing event and call unload inside like this

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) 
   Unload Me  
End Sub 

Upvotes: 0

Siddharth Rout
Siddharth Rout

Reputation: 149295

Change form.Hide to Unload Me

Upvotes: 6

Related Questions