2 Option Button Groups

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
141
Got a UserForm with 2 groups of Option buttons (OptionButtons 1&2 = Group1, OptionButton 3&4 = Group2).

I need to have text entered into a textbox depending on which options from each group are selected.
I know the code for when only using one group:

VBA Code:
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
TextBox1.Value = "Test Text"
End If

Private Sub CommandButton1_Click()
If OptionButton2.Value = True Then
TextBox1.Value = "Test Text 2"
End If

End Sub

Now I just need to know how to incorporate when selecting per-say OptionButton1 and OptionButton3, or 1&4, or 2&3, or 2&4.

Much thanks!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
put the options into 2 FRAMEs (groups).
Then the frame gets the value of the options chosen in it.
 
Upvote 0
I did manage to find out that all I have to do is add "And", for example:

VBA Code:
Private Sub CommandButton1_Click()

If OptionButton1.Value = True And OptionButton3.Value = True Then
TextBox1.Value = "Test Text 1"
End If

If OptionButton1.Value = True And OptionButton4.Value = True Then
TextBox1.Value = "Test Text 2"
End If

If OptionButton2.Value = True And OptionButton3.Value = True Then
TextBox1.Value = "Test Text 3"
End If

If OptionButton2.Value = True And OptionButton4.Value = True Then
TextBox1.Value = "Test Text 4"
End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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