How do I enable/disable checkboxes in relation to one another?

Ayugma

New Member
Joined
Nov 20, 2020
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
I have two check boxes: CheckBox2 and CheckBox5. If CheckBox2 is clicked, then CheckBox5 should be disabled. When CheckBox5 is clicked CheckBox2 is disabled. I attempted this by using the following code:

VBA Code:
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
    CheckBox5.Enabled = False
    CheckBox5.Value = False
End If
End Sub

Private Sub CheckBox5_Click()
If CheckBox5.Value = True Then
    CheckBox2.Enabled = False
    CheckBox2.Value = False
End If
End Sub

The code however does not work as intended. For some reason, CheckBox5 remains disabled, even after I have unchecked CheckBox2. Any help would be appreciates. NOTE: No I can't switch to OptionButtons.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi & welcome to MrExcel.
You are only checking if the value is true, you need to add code to re-enable the checkbox if the value is false.
 
Upvote 0
Solution
Hi,
welcome to forum
If you check say checkbox2 it disables the other - you will therefore, first have uncheck it before being able to check checkbox5

Perhaps if I have understood correctly, something like this will do what you want??

VBA Code:
Private Sub CheckBox2_Click()
    Me.CheckBox5.Enabled = Not Me.CheckBox2.Value
End Sub

Private Sub CheckBox5_Click()
    Me.CheckBox2.Enabled = Not Me.CheckBox5.Value
End Sub

Dave
 
Upvote 0
Fluff's response worked. So did dmt32. I do wonder what "Me" and "Not Me" refer to? I don't have a significant VBA experience, so if you could explain what they are and how they should be used?
 
Upvote 0
It depends on where the code is located.
In a Userform Me is the userform, if it's in a sheet module Me is the sheet.
If checkbox2 is true then the enabled property of checkbox5 is set to Not true, ie false & vice versa
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

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