Setting Default Option Value

bluegirl_1962

New Member
Joined
Jun 7, 2011
Messages
10
New to VBA.. I need to set a default option button value. There are three options and there is already code under a userform_initiialize(). How do I get started? Any direction would be appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
First you have to set the property "GroupName" (in property pane of the VBA editor). This name is the same for each item in the group.

Then it just a matter of setting the desired default's value equal to True. The other will be unmarked as only one option button within a GroupName can be equal to true at a given time.


Code:
Private Sub UserForm_Initialize()

// Sets Default selected to Option Button 1
    OptionButton1.Value = True


'// This assignment must be done before the userform 
    '// is displayed I.E. before either
    '// UserForm1.Show or Load UserForm1 is called

    '// Display Userform1
    UserForm1.Show

End Sub

As long as a prior default wasn't set in userform_initiialize() it should matter where you set the OptionButton1.Value = True as long as it before the call to .show.
 
Upvote 0
Thanks for the response but I wasn't able to make it work. This code was written by someone else and I just need to set the first option value to be default. Here's a look at the code

Private Sub UserForm_Activate()


With State_Country_Selection
.State_Combo.Clear
.Country_Combo.Clear

.Customer_Option.Value = False
.State_Option.Value = False
.Country_Option.Value = False


.State_Combo.AddItem "Northern"
.State_Combo.AddItem "Southern"
.State_Combo.AddItem "Western"

Will this help assist me further
 
Upvote 0
Sorry it didn't work for you. The problem with trying to answer user form question on a forum is that a lot of the information is not in the code but in the properties pane.

Could you provide the "(Name)" field value from the Property Pane for each of the three option buttons and also double check if they have the same "GroupName" value or no value.

Thanks
 
Upvote 0
no problem with the "not working"... I appreciate you assisting me...

No group name

Customer, State, Country are the three option names.. I want the default to be Customer

thanks again
 
Upvote 0
You could give them a common GroupName or just set all of them manually. I would suggest the latter as I don't know if it will affect anything else in the code if you were to add a group name.

Just to be clear the (Name) Fields are
"Customer", "State", "Country" and not
"Customer_Option", "State_Option", "Country_Option"
as the code you posted suggests.

If just "Customer", "State", "Country" add this to the code

Customer.Value = True
State.Value = False
Country.Value = False

If actually "Customer_Option", "State_Option", "Country_Option"

Change: Customer_Option.Value = False
To:Customer_Option.Value = True
 
Upvote 0
here's the sub... where do i put it... Sorry I'm really green @ this

Private Sub UserForm_Activate()

With Customer_State_Selection
.State_Combo.Clear
.Country_Combo.Clear

.Customer_Option.Value = False
.State_Option.Value = False
.Country_Option.Value = False

.State_Combo.AddItem "Nothern"
.State_Combo.AddItem "Southern"
.State_Combo.AddItem "Western"


End With
End Sub
 
Upvote 0
Anywhere it really doesn't matter in this case

Code:
Private Sub UserForm_Activate()

With Customer_State_Selection
.State_Combo.Clear
.Country_Combo.Clear

[B]Customer.Value = True
State.Value = False
Country.Value = False[/B]

.Customer_Option.Value = False
.State_Option.Value = False
.Country_Option.Value = False

.State_Combo.AddItem "Nothern"
.State_Combo.AddItem "Southern"
.State_Combo.AddItem "Western"


End With
End Sub
 
Upvote 0
What line in the code does does it highlight when it gives you that error. Also the (Name)s don't have "_Option" after them?
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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