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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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