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
 
Forgot to add the Initialize event
Code:
Private Sub UserForm_Initialize()
   Me.CommandButton1.Enabled = False
End Sub
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Glad we could help & thanks for the feedback
 
Upvote 0
...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
If the Enabled property for CommandButton1 is set to False in the Properties Window, then another option for your OptCheck subroutine would be this...
Code:
Private Sub UserForm_Click()
  Dim X As Long, Cnt As Long
  For X = 1 To 16
    Cnt = Cnt + Me.Controls("OptionButton" & X).Value
  Next
  CommandButton1.Enabled = (Cnt = -8)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,224
Members
453,025
Latest member
Hannah_Pham93

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