Cancel button on userform

KCIWebMaster

New Member
Joined
Mar 5, 2003
Messages
23
I've got my form and macros working now (thanks to Richie for his help). :pray:

My only problem now is that when you click on the cancel button on the form it still runs the macro before it closes the form. Where do I need to put the code for the cancel command button? Right now it's under forms but the code that calls up the form is in a macro in a module and I have a button on the spreadsheet that runs the macro and user form.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
It occured to the cancel button code. I am using VBA code.

Private Sub CommandButton_Click()
Unload Me
End Sub
 
Upvote 0
If it's clicked the code will run. If it's not clicked, it won't. Therefore you don't have to 'check' if it was clicked per se, the code will do it for you.
Private Sub CommandButton1_Click()
unload me
end
End Sub


Iam Getting an Error 361: Application defined or object defined error.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top