How to exit a sub from a userform "Cancel_Click"
Posted on 2012-09-06
I have code which loads a user form.
The userform displays a list of clients and asks for "ok" or "cancel"
ok continues the routine
cancel should exit the routine.
I'm aiming for this:
If the userform result is ok then continue
else if the userform result is cancel, then end the routine.
How does the syntax go?
My code so far within the routine is:
'Load the userform with Clientlist information
Then, the code for the Userform is:
Private Sub cmd_Cancel_Click()
Private Sub cmd_Ok_Click()
Private Sub UserForm_Initialize()
'Check that data exists in the correct sheet
If Not Range("A7") Like "acct*" Then
MsgBox "There are no client data"
Range(Cells(8, 1), Cells(8, 1).End(xlDown)).Name = "Clients"
Me.Lbox_ClientList.RowSource = Range("Clients").Address
So far i have found that either clicking OK, or Cancel leads to the routine continuing.
What is the bit of code I have missed to make it all go away?
Thanks very much!