Help Creating a User form

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
Hello,
I am totally new to creating userforms, and have done a bit of googling but either find information too basic of too confusing.

I have inserted and formatted a button into a new userform in my workbook "Userform1". I have then placed two text boxes, two labels, and one command button. I want within my code, for the form to open, and the values the user puts in either box to be passed into the module.

So in module 1

sub somecode()

code
code
code
userform1.show
storedval=userform1.textbox1.value
soredval2=userform1.textbox2.value

end sub

So I want the userform to open, user to put in some values, click the command button, the form to close and the values to pass from the textboxes into the sub somecode()
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Rather than building forms and boxes and such, cant you do the same thing with a worksheet?
Paint the cells blue, except for 2 cells (your 2 'boxes') and a button to run the macro, that reads the cells:
storeDval = range("B2").value
storeDval2 = range("B3").value

less code, less headaches.
 
Upvote 0
Sorry I should have probably mentioned that the above example is just for me to try and understand how it works, the code I will put it into is much more demanding hence the need for the userforms.
 
Upvote 0
click the command button, the form to close
Rather than closing the form you could hide it
Code:
Private Sub DoneBtn_Click()

    Me.Hide

End Sub
& then close it at the end of the sub.
Code:
    Unload TitleFrm
Exit Sub
This is how I do it
 
Upvote 0
I think this is what you're looking for...

Code:
So in module 1

public storedval as string
public soredval2 as string
public sub somecode()

code
code
code
userform1.show
storedval=userform1.textbox1.value
soredval2=userform1.textbox2.value

end sub

userform

Code:
private sub commandbutton1_click()
userform1.hide

end sub

or
Code:
private sub commandbutton1_click()

storedval = textbox1.value
soredval2 = textbox2.value
unload userform1

end sub
 
Upvote 0
I think this is what you're looking for...

Code:
So in module 1

public storedval as string
public soredval2 as string
public sub somecode()

code
code
code
userform1.show
storedval=userform1.textbox1.value
soredval2=userform1.textbox2.value

end sub

userform

Code:
private sub commandbutton1_click()
userform1.hide

end sub

or
Code:
private sub commandbutton1_click()

storedval = textbox1.value
soredval2 = textbox2.value
unload userform1

end sub

Hi,

Problem is still that the variable doesn't seem to be passing from the userform into module 1. Currently I have the following example

Code:
Public Name as String
Public Sub Search
code
code
code
userform1.show
name =  userform1.textbox1.value
end sub

the userform1 has the code

Code:
Private Sub CommandButton1_Click()
name = TextBox1.Value
storedval2 = TextBox2.Value
Unload UserForm1
End Sub

When stepping from the userform back into the search sub, the name variable never gets populated with what was entered into the userform box!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,144
Members
448,552
Latest member
WORKINGWITHNOLEADER

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