Checkbox click and uncheck other checked boxes

cpereznj

New Member
Joined
Nov 27, 2012
Messages
17
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,212
Office Version
365
Platform
Windows
Rather than using CheckBoxes why not use OptionButtons.
That way as soon as you select one the others will revert to false
 

cpereznj

New Member
Joined
Nov 27, 2012
Messages
17
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,212
Office Version
365
Platform
Windows
What is your current code?
 

cpereznj

New Member
Joined
Nov 27, 2012
Messages
17
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,212
Office Version
365
Platform
Windows
Glad you've sorted it & thanks for the feedback
 

Forum statistics

Threads
1,082,020
Messages
5,362,713
Members
400,686
Latest member
Aakash

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top