How to allow only one checkbox in a group to be selected in Excel?
In some Excel applications, you might need to let users select only one option from a group of checkboxes—mimicking the behavior of radio buttons. For example, as shown in the screenshot below, when you check one checkbox in row2, all other checkboxes in the group are instantly disabled, ensuring that only a single choice is possible at any one time. This restriction is useful in survey forms, single-answer selection lists, or dashboards where you want to prevent multiple answers. Achieving this functionality directly in Excel requires specific techniques, such as using VBA code. This article provides practical solutions to enable a "single selection" effect with checkboxes in Excel, including step-by-step instructions and important considerations for real-world usage.
Only make one checkbox to be selected with VBA code
You can use the following VBA approach to ensure only one checkbox in a group may be selected at a time. This solution is especially suitable when you need a seamless, automatic experience—ideal for complex templates or when controlling enable/disable logic is important.
1. Start by inserting the checkboxes where you want a single selection enforced. For this solution, you must use ActiveX Control checkboxes, as Form Controls checkboxes do not support the enable/disable mechanism directly. To insert ActiveX checkboxes, go to Developer tab > Insert > ActiveX Controls > Check Box. Arrange all checkboxes within your desired group as shown below:
2. Press Alt + F11 together to open the Microsoft Visual Basic for Applications window.
3. In the editor window, click Insert > Class Module. This step creates a new class module, which is required for handling events for multiple checkboxes. Using a class module makes it possible to respond to each checkbox being clicked individually, no matter how many checkboxes are present.
4. Find the new class module in the Properties pane (usually on the left), click it, and in the (Name) box, rename it from the default value (such as Class1) to ClsChk. Then, copy and paste the following code into the code window of this class module. See screenshot as reference:
VBA code1: Only select one checkbox per time
Option Explicit
Public WithEvents Chk As MSForms.CheckBox
Private Sub Chk_Click()
Call SelOneCheckBox(Chk)
End Sub
Sub SelOneCheckBox(Target As Object)
Dim xObj As Object
Dim I As String
Dim n As Integer
If Target.Object.Value = True Then
I = Right(Target.Name, Len(Target.Name) - 8)
For n = 1 To ActiveSheet.OLEObjects.Count
If n <> Int(I) Then
Set xObj = ActiveSheet.OLEObjects.Item(n)
xObj.Object.Value = False
xObj.Object.Enabled = False
End If
Next
Else
I = Right(Target.Name, Len(Target.Name) - 8)
For n = 1 To ActiveSheet.OLEObjects.Count
If n <> Int(I) Then
Set xObj = ActiveSheet.OLEObjects.Item(n)
xObj.Object.Enabled = True
End If
Next
End If
End Sub
5. Next, click Insert > Module to add a standard code module. Copy and paste the following code into the module window. This code will initialize and "link" all your checkboxes to the event handler defined above:
VBA code2: Only select one checkbox per time
Dim xCollection As New Collection
Public Sub ClsChk_Init()
Dim xSht As Worksheet
Dim xObj As Object
Dim xChk As ClsChk
Set xSht = ActiveSheet
Set xCollection = Nothing
For Each xObj In xSht.OLEObjects
If xObj.Name Like "CheckBox**" Then
Set xChk = New ClsChk
Set xChk.Chk = CallByName(xSht, xObj.Name, VbGet)
xCollection.Add xChk
End If
Next
Set xChk = Nothing
End Sub
6. Press F5 to execute the code, which activates the single-selection logic for your checkbox group. Test the behavior by checking any of the boxes; all other boxes should immediately become unchecked and disabled. Unchecking your current selection will re-enable all checkboxes so you may make a different selection.
Note: If you add or delete any checkboxes from your group, you will need to rerun the initialization VBA. This is because the event handlers are refreshed each time the code is executed, ensuring any changes to the control group are properly recognized by your VBA.
Advantages of this method include its full automation—users cannot accidentally select multiple options. However, it only works with ActiveX controls, which may be limited by Excel version, and macros need to be enabled. Also, distributing workbooks with ActiveX controls or macros to other users might require additional security permissions.
Related articles:
- How to filter data based on checkbox in Excel?
- How to hide checkbox when row is hidden in Excel?
- How to highlight cell or row with checkbox in Excel?
- How to create a drop down list with multiple checkboxes in Excel?
- How to insert date stamp into a cell if ticked a checkbox in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!