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
 

Max1616

Active Member
Joined
Nov 25, 2015
Messages
385
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,448
Office Version
365
Platform
Windows
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
 

Max1616

Active Member
Joined
Nov 25, 2015
Messages
385
Ah, that's much easier to maintain then my solution. Good thinking Fluff!
 

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hi Fluff,
How and Where do I create that sub OptCheck code?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,448
Office Version
365
Platform
Windows
Hi Fluff,
How and Where do I create that sub OptCheck code?
Just paste it into the userform module
 
Last edited:

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hey Fluff,

When I paste it into a module, it says invalid use of "me" keyword.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,448
Office Version
365
Platform
Windows
It needs to go in the UserForm Module, not a regular Module
 

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hey Fluff,

The submit button still works even when none of the buttons are checked.
 

Forum statistics

Threads
1,082,635
Messages
5,366,687
Members
400,913
Latest member
SarahMS1

Some videos you may like

This Week's Hot Topics

Top