checkbox to check automatically IF any of other checkboxes are checked

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
So here is a brief snippet of my userform i have to use as an example:
o0arfn.jpg


the top right-hand box (where it says "miscellaneous incidents") has a transparent label over top of the box so it cannot be manually checked... (i put a single frame around it only so that it can be seen for my example here...) that box is named: chkIN

I have the following checkboxes listed below the top one:
chkSUP = "supplier"
chkCON = "contractor"
chkAUD = "audit"
chkPROP = "property"
chkALA = "alarm"
chkRAIL = "railcar"
chkOTH = "other"

I need the top checkbox (chkIN) to become checked if ANY of the other boxes are checked. (and then when nothing is checked within that group of boxes, the chkIN in turn will also become unchecked.)

I have (simple) code throughout my userforms where i can check or uncheck boxes based on whether another box is checked/unchecked... but NOT when it involves multiple checkboxes like I do here.

Here is my simple code I use when I am just using 1 box to change the other box... but I cannot figure out how to use "or" in this so i can include other checkboxes and their status...
Code:
Private Sub chkNo_Change()
If chkNo.Value = True Then chkYes = False
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What if I have checkboxes on the form that I want excluded from the other grouped checkboxes? Is there a easy way to go about this? (there are only 2, and if that cant easily be done, I can use something else in lieu of checkboxes for those.. not a big deal... just thought I'd ask tho. :) ) Thank you
 
Upvote 0
in this part:

Code:
Private Sub UserForm_Initialize()




'Load all the checkboxes in a class
    Dim ctlLoop As MSForms.Control
    Dim clsObject As Class1
    
    Set colCheck = New Collection
    For Each ctlLoop In Me.Controls
        If TypeName(ctlLoop) = "CheckBox" Then
             select ctlLoop.name
                case "textbox1", "textbox2"
                
                case else
                Set clsObject = New Class1
                Set clsObject.chbCustom1 = ctlLoop
                colCheck.Add clsObject
            end select
        End If
    Next ctlLoop
    loading = False
'end Load




End Sub
 
Upvote 0
in this part:

Code:
Private Sub UserForm_Initialize()
'Load all the checkboxes in a class
    Dim ctlLoop As MSForms.Control
    Dim clsObject As Class1
    
    Set colCheck = New Collection
    For Each ctlLoop In Me.Controls
        If TypeName(ctlLoop) = "CheckBox" Then
             select ctlLoop.name
                case "textbox1", "textbox2"
                
                case else
                Set clsObject = New Class1
                Set clsObject.chbCustom1 = ctlLoop
                colCheck.Add clsObject
            end select
        End If
    Next ctlLoop
    loading = False
'end Load
End Sub

Hello DanteAmor, thank you for the code. However, I am running into this error:
I tried placing the 'select ctlLoop' part up on the same line as the 'Then', but I get the sasame error... Do I not have the code in the correct place, maybe? (im wondering if its not working due to me having existing code already within the 'UserForm_Initialize' procedure and that is causing the conflict...)
Thanks again for you help
29xi5oi.jpg
 
Upvote 0
Hello DanteAmor, thank you for the code. However, I am running into this error:
I tried placing the 'select ctlLoop' part up on the same line as the 'Then', but I get the sasame error... Do I not have the code in the correct place, maybe? (im wondering if its not working due to me having existing code already within the 'UserForm_Initialize' procedure and that is causing the conflict...)
Thanks again for you help


must be:

Code:
[COLOR=#333333]select [/COLOR][COLOR=#0000ff]Case [/COLOR][COLOR=#333333]ctlLoop.name[/COLOR]

Sorry
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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