How to set default Values for a Userfrom and call the Userform

PETLECLS1

New Member
Joined
Nov 20, 2017
Messages
7
When I click the button that calls up the userform, the userform comes up, but none of the default values I have picked show. I am using Excel 2010.

How do I fix my code?
Code:
Sub NewTranslationRequest()'Fill Default Data
 OptionButton1 = True
 OptionButton2 = False
 OptionButton3 = False
 OptionButton4 = True
 OptionButton5 = False
 OptionButton6 = True
 OptionButton7 = False
 OptionButton8 = True
 OptionButton9 = True
 OptionButton10 = False
 OptionButton11 = True
 CheckBox1 = True
 CheckBox2 = True
 CheckBox3 = True
 CheckBox4 = True
 CheckBox5 = False
 CheckBox6 = False
 CheckBox7 = False
 
 'Clear previous data
 ComboBox1 = ""
 TextBox4 = ""
 TextBox1 = ""
 TextBox2 = ""
 TestBox3 = ""
UserFormNewRequest.Show
End Sub
 
Last edited by a moderator:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You need to set the values in an initialize event
Code:
Private Sub UserForm_Initialize()
OptionButton1 = True
OptionButton2 = False
OptionButton3 = False
OptionButton4 = True
OptionButton5 = False
OptionButton6 = True
OptionButton7 = False
OptionButton8 = True
OptionButton9 = True
OptionButton10 = False
OptionButton11 = True
CheckBox1 = True
CheckBox2 = True
CheckBox3 = True
CheckBox4 = True
CheckBox5 = False
CheckBox6 = False
CheckBox7 = False
End Sub
 
Upvote 0
If you want default values, you can set them at design time. Alternatively, you need to qualify the controls with the userform object
Code:
Sub NewTranslationRequest()'Fill Default Data
With UserFormNewRequest
.OptionButton1 = True
.OptionButton2 = False
.OptionButton3 = False
.OptionButton4 = True
.OptionButton5 = False
.OptionButton6 = True
.OptionButton7 = False
.OptionButton8 = True
.OptionButton9 = True
.OptionButton10 = False
.OptionButton11 = True
.CheckBox1 = True
.CheckBox2 = True
.CheckBox3 = True
.CheckBox4 = True
.CheckBox5 = False
.CheckBox6 = False
.CheckBox7 = False

'Clear previous data
.ComboBox1 = ""
.TextBox4 = ""
.TextBox1 = ""
.TextBox2 = ""
.TestBox3 = ""
.Show
end with
End Sub
 
Last edited:
Upvote 0
Thanks guys! I had to tweak it a little as I had a typo and added an extra option button. But the code works now! :)
Code:
Sub NewTranslationRequest()
'Fill Default Data
With UserFormNewRequest
.OptionButton1 = True
.OptionButton2 = False
.OptionButton3 = False
.OptionButton4 = True
.OptionButton5 = False
.OptionButton6 = True
.OptionButton7 = False
.OptionButton8 = True
.OptionButton9 = True
.OptionButton10 = False
.CheckBox1 = True
.CheckBox2 = True
.CheckBox3 = True
.CheckBox4 = True
.CheckBox5 = False
.CheckBox7 = False
.CheckBox8 = False

'Clear previous data
.ComboBox1 = ""
.TextBox4 = ""
.TextBox1 = ""
.TextBox2 = ""
.TextBox3 = ""
.Show
End With
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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