UserForm Validating Radio Buttons Are Clicked

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hi All,

I have a UserForm with 16 Radio Buttons (8 groups of "Yes" Or "No"). (They Are Named OptionButton1,2,3,4,5,etc.)
I have a submit button - CommandButton1

I am trying to disable the "Submit" button until at least one button from each of the 8 groups are clicked. If each group has a button checked then I want the Submit Button to be enabled and display a message ("Thank you for completing")

Currently when I open the userform none of the buttons are checked and the submit button is disabled which is perfect, but when I click on at least one button from each group, the button is still disabled.
Below is my code. I'm not sure why the button is not enabling when requirement is met. Thank you for your help!

Private Sub UserForm_Initialize()
If OptionButton1.Value = False And OptionButton2.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton3.Value = False And OptionButton4.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton5.Value = False And OptionButton6.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton7.Value = False And OptionButton8.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton9.Value = False And OptionButton10.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton11.Value = False And OptionButton12.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton13.Value = False And OptionButton14.Value = False Then
CommandButton1.Enabled = False
ElseIf OptionButton15.Value = False And OptionButton16.Value = False Then
CommandButton1.Enabled = False
Else
CommandButton1.Enabled = True
End If
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello,

I think the best way is to write a check for every time someone chooses an option.

I would so something like this:

Code:
Private Sub CommandButton1_Click()
'Code Goes Here
End Sub

Private Sub OptionButton1_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton2_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton3_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton4_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton5_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton6_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton7_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton8_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton9_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton10_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton11_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton12_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton13_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton14_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton15_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub
Private Sub OptionButton16_Click()
Dim Chk As Integer

If OptionButton1.Value = True Or OptionButton2.Value = True Then Chk = Chk + 1
If OptionButton3.Value = True Or OptionButton4.Value = True Then Chk = Chk + 1
If OptionButton5.Value = True Or OptionButton6.Value = True Then Chk = Chk + 1
If OptionButton7.Value = True Or OptionButton8.Value = True Then Chk = Chk + 1
If OptionButton9.Value = True Or OptionButton10.Value = True Then Chk = Chk + 1
If OptionButton11.Value = True Or OptionButton12.Value = True Then Chk = Chk + 1
If OptionButton13.Value = True Or OptionButton14.Value = True Then Chk = Chk + 1
If OptionButton15.Value = True Or OptionButton16.Value = True Then Chk = Chk + 1

If Chk = 8 Then CommandButton1.Enabled = True
If Chk < 8 Then CommandButton1.Enabled = False
End Sub

Private Sub UserForm_Initialize()
CommandButton1.Enabled = False
End Sub
 
Upvote 0
Another option would be.
use an on click event for each optionbutton like
Code:
Private Sub OptionButton1_Click()
    Call OptCheck
End Sub
Private Sub OptionButton2_Click()
    Call OptCheck
End Sub
and have a separate sub
Code:
Sub OptCheck()

If Not Me.OptionButton1 And Not Me.OptionButton2 Then Exit Sub
If Not Me.OptionButton3 And Not Me.OptionButton4 Then Exit Sub
If Not Me.OptionButton5 And Not Me.OptionButton6 Then Exit Sub
If Not Me.OptionButton7 And Not Me.OptionButton8 Then Exit Sub
If Not Me.OptionButton9 And Not Me.OptionButton10 Then Exit Sub
If Not Me.OptionButton11 And Not Me.OptionButton12 Then Exit Sub
If Not Me.OptionButton13 And Not Me.OptionButton14 Then Exit Sub
If Not Me.OptionButton15 And Not Me.OptionButton16 Then Exit Sub

Me.CommandButton1.Enabled = True
End Sub
 
Upvote 0
Ah, that's much easier to maintain then my solution. Good thinking Fluff!
 
Upvote 0
It needs to go in the UserForm Module, not a regular Module
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
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