Checkbox click and uncheck other checked boxes

cpereznj

New Member
Joined
Nov 27, 2012
Messages
19
I have searched my issue with no success so far. Hoping someone can point me in the right direction. I have a file with many checkboxes. For example: checkbox1, checkbox2, etc. I would like to check any checkbox and uncheck others at the same time. If checkbox1 is already checked and I click on checkbox2, it will then uncheck checkbox1 and check checkbox2.

Code:
Option Explicit

Private Sub CheckBox1_Click()
    'Turn off screen updating
    Application.ScreenUpdating = False


    If CheckBox1.Value = True Then
        
        CheckBox2.Value = 0
        CheckBox2.Enabled = True
        
        CheckBox3.Value = False
        CheckBox3.Enabled = True
        
        CheckBox4.Value = False
        CheckBox4.Enabled = True
    
            Worksheets("Score").Activate
                'Unprotect the "Score" worksheet
                ActiveSheet.Unprotect Password:=""
            Sheet3.Range("B8").Value = 10 'Checked
            Sheet3.Range("D8").Value = "" 'Unchecked
            Sheet3.Range("F8").Value = "" 'Unchecked
            Sheet3.Range("H8").Value = "" 'Unchecked
                'Protects the "Score" worksheet
                ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True _
                , AllowFiltering:=True, AllowUsingPivotTables:=True
            Worksheets("Request").Activate
    Else
        CheckBox1.Value = False
        
        CheckBox2.Value = False
        CheckBox2.Enabled = True
        
        CheckBox3.Value = False
        CheckBox3.Enabled = True
        
        CheckBox4.Value = False
        CheckBox4.Enabled = True
        
            Worksheets("Score").Activate
                'Unprotect the "Score" worksheet
                ActiveSheet.Unprotect Password:=""
            Sheet3.Range("B8").Value = "" 'Unchecked
                'Protects the "Score" worksheet
                ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True _
                , AllowFiltering:=True, AllowUsingPivotTables:=True
            Worksheets("Request").Activate
    End If
        
    'Turn on screen updating
    Application.ScreenUpdating = True
    
End Sub
    
Private Sub CheckBox2_Click()
    'Turn off screen updating
    Application.ScreenUpdating = False
    
    If CheckBox2.Value = True Then
        
        CheckBox1.Value = 0
        CheckBox1.Enabled = True
        
        CheckBox3.Value = False
        CheckBox3.Enabled = True
        
        CheckBox4.Value = False
        CheckBox4.Enabled = True
    
            Worksheets("Score").Activate
                'Unprotect the "Score" worksheet
                ActiveSheet.Unprotect Password:=""
            Sheet3.Range("D8").Value = 60 'Checked
            Sheet3.Range("B8").Value = "" 'Unchecked
            Sheet3.Range("F8").Value = "" 'Unchecked
            Sheet3.Range("H8").Value = "" 'Unchecked
                'Protects the "Score" worksheet
                ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True _
                , AllowFiltering:=True, AllowUsingPivotTables:=True
            Worksheets("Request").Activate
    Else
        CheckBox2.Value = False
        
        CheckBox1.Value = False
        CheckBox1.Enabled = True
        
        CheckBox3.Value = False
        CheckBox3.Enabled = True
        
        CheckBox4.Value = False
        CheckBox4.Enabled = True
        
            Worksheets("Score").Activate
                'Unprotect the "Score" worksheet
                ActiveSheet.Unprotect Password:=""
            Sheet3.Range("D8").Value = "" 'Unchecked
                'Protects the "Score" worksheet
                ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True _
                , AllowFiltering:=True, AllowUsingPivotTables:=True
            Worksheets("Request").Activate
    End If
    
    'Turn on screen updating
    Application.ScreenUpdating = True
    
End Sub
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Rather than using CheckBoxes why not use OptionButtons.
That way as soon as you select one the others will revert to false
 
Upvote 0
Thank you Fluff. OptionButtons will work as well. I have already added them to the file. Having a problem passing the values when the OptionButtons are checked. I have tried the similar approach on my original code but it did not work. Any ideas?
 
Upvote 0
What is your current code?
 
Upvote 0
Hi Fluff, I just answered my own question. My code was posted in the original question. I added ActiveX optionbuttons. I then changed my code with the proper optionbutton numbers and assigned the proper group boxes to make them work. I am now getting the values passed as expected. Thank you so much for the tip and the help.
 
Upvote 0
Glad you've sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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