Need help with button in userform

eus1217

New Member
Joined
Sep 18, 2006
Messages
3
I only know how to use ok/cancel buttons in IF statement format. I'm using ok/cancel in a userform.

I know to input the results of the userform on a button (i.e. 'OK'), I put in 'unload userform_name'. What command will not submit the results of the userform, as in cancel it? 'xxxx userform_name' <---what goes in xxxx? Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
If your UserForm buttons change cell values before you close the form, you need to assign the original values to variables, then have the cancel button assign those values back to the correct cells if cancel is chosen.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Sorry it's not clear what you mean, to me anyway.:eek:

What do you actually want to do?

Buttons on userforms are different from those on say an input/message box.

You have to write code to tell VBA what to do when they are pressed.

They don't really have a value, but something will this will run.
Code:
Private Sub CommandButton1_Click()
    MsgBox CommandButton1.Value
End Sub
 

eus1217

New Member
Joined
Sep 18, 2006
Messages
3
OK, let me reword it. The userform inputs data on the spreadsheet via textboxes. I just want to be able to just cancel out and close the userform with no input transferred to the form.

Also, on the userform it transfers data from the textbook on the userform to the spreadsheet as I jump from textbox to textbox. I don't want that. I want it to hold the data until I click 'submit' or 'ok' then change the fields. What code will do this? Thanks
 

eus1217

New Member
Joined
Sep 18, 2006
Messages
3
OK, let me reword it. The userform inputs data on the spreadsheet via textboxes. I just want to be able to just cancel out and close the userform with no input transferred to the spreadsheet via the userform.

Also, on the userform it transfers data from the textbox on the userform to the spreadsheet as I jump from textbox to textbox. I don't want that. I want it to hold the data until I click 'submit' or 'ok' then change the fields. What code will do this? Thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Well all you need to do is put the code to put the data on the worksheet in the Click event of the submit/ok button.

In your cancel button you could just try this.
Code:
Private Sub Cancel_Click()
    Unload Me
End Sub
 

Forum statistics

Threads
1,136,652
Messages
5,677,007
Members
419,668
Latest member
DharmaK

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
Top