Option required

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
554
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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