Userform - allow only 1 checkbox to be selected

johnohio

New Member
Joined
May 12, 2005
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I am creating a online multiple choice quiz in excel.

I only want the user to select 1 answer. So if they selected another answer the all the others are unchecked.
I just can't figure it out.

So there is the setup of the test....




VBA Code:
Private Sub UserForm_Initialize()
'multiple choice

Dim res As Worksheet
Set res = Worksheets("RESULT")

Dim su As Worksheet
Set su = Worksheets("setup")

Me.Label3 = res.Cells(Gline, 7)

'determin # of answers
ans = 4

If su.Cells(Gline, 7) = "" Then ans = 3
If su.Cells(Gline, 6) = "" Then ans = 2

Me.CheckBox1.Caption = res.Cells(Gline, 9)
Me.CheckBox2.Caption = res.Cells(Gline, 10)

If res.Cells(Gline, 11) <> "" Then
    Me.CheckBox3.Caption = res.Cells(Gline, 11)
     Else
    Me.CheckBox3.Visible = False
    End If
    
If res.Cells(Gline, 12) <> "" Then
    Me.CheckBox4.Caption = res.Cells(Gline, 12)
    
    Else
    Me.CheckBox4.Visible = False
    
    End If


End Sub

I want only one answered to be selected. So if the user clicks on answer any other checkbox becomes unchecked.

(Hope this makes sense)
Thanks!
 

Attachments

  • Capture.GIF
    Capture.GIF
    151 KB · Views: 5

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.
Instead of checkbox, you should use optionbutton controls:

1701788341413.png
 
Upvote 0
Solution

Forum statistics

Threads
1,215,209
Messages
6,123,646
Members
449,111
Latest member
ghennedy

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