Option required

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
Suggestions on how to add code to require Option?

UserForm1 includes 2 OptionButtons
If neither OptionButton is True Then
MsgBox "Option Required"

Code:
Private Sub CommandButton1_Click()
With Sheet11
Sheet11.Unprotect
    Set ws = Sheet11
 
    PName = UF1.ComboBox1.Value
    Set CLoc = ws.Columns("C:C").Find(What:=PName, after:=ws.Cells(1, 3), LookIn:= _
                            xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _
                            xlNext, MatchCase:=False, SearchFormat:=False)
        iRow = CLoc.Row
 
    ws.Cells(iRow, 14) = "A"
    ws.Cells(iRow, 15) = Date
   
    If OptionButton1 = True Then
    ws.Cells(iRow, 16) = "Cash"
    Else
    ws.Cells(iRow, 16) = "Ck#" & TextBox1.Value
    End If
 
End With
Unload Me
 
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this.
Code:
If Not(Option1.Value Or Option2.Value) Then
    MsgBox "Option required!", "No option"
    Exit Sub
End If
 
Upvote 0
You might prefer Norie's solution, but here's a similar way...

Code:
Private Sub CommandButton1_Click()
    If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False Then
        MsgBox "Option Required", vbExclamation
        Exit Sub
    End If
    'etc
    '
    '
End Sub

Also, since you're using a "With/End With" statement, you can replace...

Code:
Sheet11.Unprotect

with

Code:
.Unprotect

Hope this helps!
 
Last edited:
Upvote 0
Perhaps the simplest way would be to have one option button checked by default when the userform was opened. Let the user change the default selection if they choose, but don't force them to click.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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