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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

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