Checkboxes

kajettinc

New Member
Joined
Mar 11, 2009
Messages
15
I need to format multiple pairs of checkboxes that disable one another. e.g. if one box is checked, the other one is automatically unchecked. I am not real familiar with VBA, but am willing to test the waters. Any assistance would be greatly appreciated.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You're in luck, I just explained how to do this exactly for someone else here at work. :) My first comment to him was to use radio buttons instead of checkboxes since it does it all inherently, but he neede check boxes so where is what it came down to.

If radio buttons will work for you then try this: http://www.mrexcel.com/forum/showthread.php?t=572577

You can use active x or form control check boxex.

For form control check boxes, they are linked to a cell which will return a true or false. You can also assign a macro to be run when a checkbox is clicked, so by assigning this macro, on one check box it will toggle the other.

Code:
Sub checkchecks()
    If [j3].Value = True Then
        [j7].Value = False
    Else: [j7].Value = True
    End If
End Sub

If you use activex check boxes then you can assign code to the control itself. Here s the code of one check box, you can alter it for the second one.

Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
    CheckBox2.Value = False
    Else: CheckBox2.Value = True
    End If
End Sub

Hope one of these works for you!
 
Upvote 0
HI C Watts

This was really useful for me. Thanks for your help, and thanks for asking kajettinc.

I have an additional question. (Sorry im new to VB and finding it all a bit tricky!)

But if I have 3 (Or more) check boxes how would I write the code. I have managed to do it so that two out of the three can be checked, but I only want one to be checked!

Thanks for your help.

I hope this will all make sense soon. :)
 
Upvote 0
Which kind of check box did you make? Form Controls or Active X? And what is your is it possible that your users can deselect all three check boxes or must one always be checked?
 
Upvote 0
Hi CWatts

Sorry for the delayed response! I still need help if you can.

I used the forms control. The users can deselect all three, but cannot select more than one.

Ideally one will be chosen but it is up to them. I dont want a default choice.

i hope that helps... you help me

Its very appreciated. :biggrin:
 
Upvote 0
For this example, I created 3 check boxes and linked them to A1, A2, and A3. The check boxes change the values of those cells, just as changes to those cells change the check box values.

Assign the macros to the appropriate check box for your desired results. They should be straight-forward enough so you should have no trouble modifying them if needed.

Code:
Sub CheckBox1_Test()
If Range("A1").Value Then
    Range("A2").Value = False
    Range("A3").Value = False
    End If
End Sub
Code:
Sub CheckBox2_Test()
If Range("A2").Value Then
    Range("A1").Value = False
    Range("A3").Value = False
    End If
End Sub
Code:
Sub CheckBox3_Test()
If Range("A3").Value Then
    Range("A1").Value = False
    Range("A2").Value = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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