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
 
Try this:

Call sub check_groups with 3 arguments, the group number (1,2,3 or 4), the checkbox and the group check
I did just find one minor issue with the code... it only works with whatever Case number comes first in the code below...so the way it is listed below, its only looking at 'Case 1' grouping of checkboxes and ignores whatever is checked/unchecked in the Case 2 grouping and Case 3 grouping... I determined this by moving the 'Case 2' code up in front of the 'Case 1' and determined thats what its doing because then it was only checking the Case 2 group and ignoring Case 1 grouping of checkboxes. (hope that makes sense... its pretty simple, but I managed to make it complicated with my explantion lol)
Code:
    Select Case grp
        Case 1
            checks = Array(chkSUP, chkCON, chkAUD, chkPROP, chkALA, chkRAIL, chkOTH)
        Case 2
            checks = Array(chkleakin, chkOff, chkPerfor, chkConta, chkdoesnt)
        Case 3
            checks = Array(chkprocfai, chkprocinter, chkcontaissue)
    End Select
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I did just find one minor issue with the code... it only works with whatever Case number comes first in the code below...so the way it is listed below, its only looking at 'Case 1' grouping of checkboxes and ignores whatever is checked/unchecked in the Case 2 grouping and Case 3 grouping... I determined this by moving the 'Case 2' code up in front of the 'Case 1' and determined thats what its doing because then it was only checking the Case 2 group and ignoring Case 1 grouping of checkboxes. (hope that makes sense... its pretty simple, but I managed to make it complicated with my explantion lol)
Code:
    Select Case grp
        Case 1
            checks = Array(chkSUP, chkCON, chkAUD, chkPROP, chkALA, chkRAIL, chkOTH)
        Case 2
            checks = Array([COLOR=#0000ff]chkleakin[/COLOR], chkOff, chkPerfor, chkConta, chkdoesnt)
        Case 3
            checks = Array(chkprocfai, chkprocinter, chkcontaissue)
    End Select


Are you doing the following with case 2?
Code:
Private Sub [COLOR=#0000ff]chkleakin_Click[/COLOR]()
    Call check_groups([COLOR=#ff0000]2[/COLOR], [COLOR=#0000ff]chkleakin[/COLOR], [COLOR=#008000]chkNameOfCheckgroup2[/COLOR])
End Sub

Or put the final code that you have.
 
Upvote 0
Are you doing the following with case 2?
Code:
Private Sub [COLOR=#0000ff]chkleakin_Click[/COLOR]()
    Call check_groups([COLOR=#ff0000]2[/COLOR], [COLOR=#0000ff]chkleakin[/COLOR], [COLOR=#008000]chkNameOfCheckgroup2[/COLOR])
End Sub

Or put the final code that you have.

Here is the code that I am running (everything runs as intended (without any errors or hiccups I mean) except that it ignores case 2, 3 and 4 (whatever case I put in the #1 position it will work just for that group.)


Code:
[COLOR=#008000]' *****************************************************************************************************[/COLOR]
[COLOR=#008000]' THIS IS THE GROUP (FIRST GROUP) FOR ENVIRONMENTAL, HEALTH & SAFETY ( "EHS1" )[/COLOR]

Private Sub chkEHS_injury_Click()
    Call check_groups(EHS1, chkEHS_injury, chkEHS)
End Sub
Private Sub chkEHS_NM_Click()
    Call check_groups(EHS1, chkEHS_NM, chkEHS)
End Sub
Private Sub chkEHS_STF_Click()
    Call check_groups(EHS1, chkEHS_STF, chkEHS)
End Sub
Private Sub chkEHS_struck_Click()
    Call check_groups(EHS1, chkEHS_struck, chkEHS)
End Sub
Private Sub chkEHS_expose_Click()
    Call check_groups(EHS1, chkEHS_expose, chkEHS)
End Sub
Private Sub chkEHS_splash_Click()
    Call check_groups(EHS1, chkEHS_splash, chkEHS)
End Sub
Private Sub chkEHS_respir_Click()
    Call check_groups(EHS1, chkEHS_respir, chkEHS)
End Sub
Private Sub chkEHS_spill_Click()
    Call check_groups(EHS1, chkEHS_spill, chkEHS)
End Sub
Private Sub chkEHS_mobile_Click()
    Call check_groups(EHS1, chkEHS_mobile, chkEHS)
End Sub
Private Sub chkEHS_gas_Click()
    Call check_groups(EHS1, chkEHS_gas, chkEHS)
End Sub
Private Sub chkEHS_other_Click()
    Call check_groups(EHS1, chkEHS_other, chkEHS)
End Sub

[COLOR=#008000]' *****************************************************************************************************[/COLOR]
[COLOR=#008000]' THIS IS THE GROUP (SECOND GROUP) FOR CUSTOMER SERVICE ISSUES ( "CSR2" )[/COLOR]

Private Sub chkCSR_PC_leak_Click()
    Call check_groups(CSR2, chkCSR_PC_leak, chkCSR)
End Sub
Private Sub chkCSR_PC_color_Click()
    Call check_groups(CSR2, chkCSR_PC_color, chkCSR)
End Sub
Private Sub chkCSR_PC_perform_Click()
    Call check_groups(CSR2, chkCSR_PC_perform, chkCSR)
End Sub
Private Sub chkCSR_PC_contam_Click()
    Call check_groups(CSR2, chkCSR_PC_contam, chkCSR)
End Sub
Private Sub chkCSR_PC_look_Click()
    Call check_groups(CSR2, chkCSR_PC_look, chkCSR)
End Sub
Private Sub chkCSR_LABE_hazLabel_Click()
    Call check_groups(CSR2, chkCSR_LABE_hazLabel, chkCSR)
End Sub
Private Sub chkCSR_LABE_xLabel_Click()
    Call check_groups(CSR2, chkCSR_LABE_xLabel, chkCSR)
End Sub
Private Sub chkCSR_LABE_mLabel_Click()
    Call check_groups(CSR2, chkCSR_LABE_mLabel, chkCSR)
End Sub
Private Sub chkCSR_LABE_pLabel_Click()
    Call check_groups(CSR2, chkCSR_LABE_pLabel, chkCSR)
End Sub
Private Sub chkCSR_PACK_lids_Click()
    Call check_groups(CSR2, chkCSR_PACK_lids, chkCSR)
End Sub
Private Sub chkCSR_PACK_xPack_Click()
    Call check_groups(CSR2, chkCSR_PACK_xPack, chkCSR)
End Sub
Private Sub chkCSR_PACK_fPack_Click()
    Call check_groups(CSR2, chkCSR_PACK_fPack, chkCSR)
End Sub
Private Sub chkCSR_PACK_mPack_Click()
    Call check_groups(CSR2, chkCSR_PACK_mPack, chkCSR)
End Sub
Private Sub chkCSR_bill_Click()
    Call check_groups(CSR2, chkCSR_bill, chkCSR)
End Sub
Private Sub chkCSR_ship_Click()
    Call check_groups(CSR2, chkCSR_ship, chkCSR)
End Sub
Private Sub chkCSR_slop_Click()
    Call check_groups(CSR2, chkCSR_slop, chkCSR)
End Sub
Private Sub chkCSR_shipper_Click()
    Call check_groups(CSR2, chkCSR_shipper, chkCSR)
End Sub
Private Sub chkCSR_other_Click()
    Call check_groups(CSR2, chkCSR_other, chkCSR)
End Sub

[COLOR=#008000]' *****************************************************************************************************[/COLOR]
[COLOR=#008000]' THIS IS THE GROUP (THIRD GROUP) FOR SEATEX INTERNAL ISSUES ( "INT3" )[/COLOR]

Private Sub chkSEAI_proF_Click()
    Call check_groups(INT3, chkSEAI_proF, chkSEAI)
End Sub
Private Sub chkSEAI_proI_Click()
    Call check_groups(INT3, chkSEAI_proI, chkSEAI)
End Sub
Private Sub chkSEAI_contam_Click()
    Call check_groups(INT3, chkSEAI_contam, chkSEAI)
End Sub
Private Sub chkSEAI_mech_Click()
    Call check_groups(INT3, chkSEAI_mech, chkSEAI)
End Sub
Private Sub chkSEAI_docu_Click()
    Call check_groups(INT3, chkSEAI_docu, chkSEAI)
End Sub
Private Sub chkSEAI_pers_Click()
    Call check_groups(INT3, chkSEAI_pers, chkSEAI)
End Sub
Private Sub chkSEAI_raw_Click()
    Call check_groups(INT3, chkSEAI_raw, chkSEAI)
End Sub
Private Sub chkSEAI_leak_Click()
    Call check_groups(INT3, chkSEAI_leak, chkSEAI)
End Sub
Private Sub chkSEAI_work_Click()
    Call check_groups(INT3, chkSEAI_work, chkSEAI)
End Sub
Private Sub chkSEAI_other_Click()
    Call check_groups(INT3, chkSEAI_other, chkSEAI)
End Sub

[COLOR=#008000]' *****************************************************************************************************[/COLOR]
[COLOR=#008000]' THIS IS THE GROUP (FOURTH GROUP) FOR MISCELLANEOUS INCIDENTS ( "MISC4" )[/COLOR]

Private Sub chkMISC_supplier_Click()
    Call check_groups(MISC4, chkMISC_supplier, chkMISC)
End Sub
Private Sub chkMISC_contract_Click()
    Call check_groups(MISC4, chkMISC_contract, chkMISC)
End Sub
Private Sub chkMISC_finding_Click()
    Call check_groups(MISC4, chkMISC_finding, chkMISC)
End Sub
Private Sub chkMISC_theft_Click()
    Call check_groups(MISC4, chkMISC_theft, chkMISC)
End Sub
Private Sub chkMISC_alarm_Click()
    Call check_groups(MISC4, chkMISC_alarm, chkMISC)
End Sub
Private Sub chkMISC_rail_Click()
    Call check_groups(MISC4, chkMISC_rail, chkMISC)
End Sub
Private Sub chkMISC_rose_Click()
    Call check_groups(MISC4, chkMISC_rose, chkMISC)
End Sub
Private Sub chkMISC_elcampo_Click()
    Call check_groups(MISC4, chkMISC_elcampo, chkMISC)
End Sub
Private Sub chkMISC_other_Click()
    Call check_groups(MISC4, chkMISC_other, chkMISC)
End Sub

[COLOR=#008000]' *****************************************************************************************************[/COLOR]

Sub check_groups(grp, checkb As MSForms.CheckBox, checkG As MSForms.CheckBox)
    Dim checks As Variant, i As Long, n As Long
    
    Select Case grp

        Case EHS1
            checks = Array(chkEHS_injury, chkEHS_NM, chkEHS_STF, chkEHS_struck, chkEHS_expose, _
            chkEHS_splash, chkEHS_respir, chkEHS_spill, chkEHS_mobile, chkEHS_gas, chkEHS_other)
            
        Case CSR2
            checks = Array(chkCSR_PC_leak, chkCSR_PC_color, chkCSR_PC_perform, chkCSR_PC_contam, _
            chkCSR_PC_look, chkCSR_LABE_hazLabel, chkCSR_LABE_xLabel, chkCSR_LABE_mLabel, _
            chkCSR_LABE_pLabel, chkCSR_PACK_lids, chkCSR_PACK_xPack, chkCSR_PACK_fPack, _
            chkCSR_PACK_mPack, chkCSR_bill, chkCSR_ship, chkCSR_slop, chkCSR_shipper, chkCSR_other)
            
        Case INT3
            checks = Array(chkSEAI_proF, chkSEAI_proI, chkSEAI_contam, chkSEAI_mech, _
            chkSEAI_docu, chkSEAI_pers, chkSEAI_raw, chkSEAI_leak, chkSEAI_work, chkSEAI_other)
            
        Case MISC4
            checks = Array(chkMISC_supplier, chkMISC_contract, chkMISC_finding, chkMISC_theft, _
            chkMISC_alarm, chkMISC_rail, chkMISC_rose, chkMISC_elcampo, chkMISC_other)
            
    End Select
    For i = 0 To UBound(checks)
        If checks(i).Value = True Then
            n = n + 1
            If n = 3 Then
                MsgBox "Please select a maximum of 2 categories"
                checkb = False
            End If
            checkG = True
        End If
    Next
    If n = 0 Then checkG = False
End Sub
[COLOR=#008000]' *****************************************************************************************************[/COLOR]

PS- I also confirmed that within the properties for each of the checkboxs that appear on the userform object that all the 'group names' are correct under the "GroupName" field.

Thank you DanteAmor
icon14.png




21dr1ci.jpg
 
Upvote 0
Why are you doing this:

Code:
Call check_groups([SIZE=3][B][COLOR=#ff0000]EHS1[/COLOR][/B][/SIZE], chkEHS_injury, chkEHS)

There you must put a number: 1, 2, 3 or 4

Just put the number

Code:
Call check_groups([SIZE=3][B][COLOR=#ff0000]1[/COLOR][/B][/SIZE], chkEHS_injury, chkEHS)

Code:
Select Case grp


        Case 1
            checks = Array(chkEHS_injury, chkEHS_NM, chkEHS_STF, chkEHS_struck, chkEHS_expose, _
            chkEHS_splash, chkEHS_respir, chkEHS_spill, chkEHS_mobile, chkEHS_gas, chkEHS_other)
            
        Case 2
            checks = Array(chkCSR_PC_leak, chkCSR_PC_color, chkCSR_PC_perform, chkCSR_PC_contam, _
            chkCSR_PC_look, chkCSR_LABE_hazLabel, chkCSR_LABE_xLabel, chkCSR_LABE_mLabel, _
            chkCSR_LABE_pLabel, chkCSR_PACK_lids, chkCSR_PACK_xPack, chkCSR_PACK_fPack, _
            chkCSR_PACK_mPack, chkCSR_bill, chkCSR_ship, chkCSR_slop, chkCSR_shipper, chkCSR_other)
            
        Case 3
            checks = Array(chkSEAI_proF, chkSEAI_proI, chkSEAI_contam, chkSEAI_mech, _
            chkSEAI_docu, chkSEAI_pers, chkSEAI_raw, chkSEAI_leak, chkSEAI_work, chkSEAI_other)
            
        Case 4
            checks = Array(chkMISC_supplier, chkMISC_contract, chkMISC_finding, chkMISC_theft, _
            chkMISC_alarm, chkMISC_rail, chkMISC_rose, chkMISC_elcampo, chkMISC_other)
            
    End Select
 
Last edited:
Upvote 0
Why are you doing this:

Code:
Call check_groups([SIZE=3][B][COLOR=#ff0000]EHS1[/COLOR][/B][/SIZE], chkEHS_injury, chkEHS)

There you must put a number: 1, 2, 3 or 4

Just put the number

:banghead:

Sorry.

I see now what you mean. That totally fixed it.
 
Upvote 0
Do not worry, it happens to everyone, haha.
I'm glad it works for you already.
 
Upvote 0
Last question... (I swear this time :pray:)

I just ran into something else that I didnt think about... First of all... if.. this is going to be too difficult or just going to be a giant PITA, then what I have is fine (really), I can make it work. But hopefully what I am going to describe here can be done with a relatively simple fix...

Here is my example; If anything in group 2 is checked... which means by default that the very top box (which is the chkCSR box for group 2) then no boxes in group 3 or 4 can be checked. BUT... group 1 still could be... (or, maybe not... group 1 is to be optional and independent of what happens in groups 2-4.)

The same is going to be true for the other 2 groups (groups 3 and groups 4)... If anything is checked in 3, then 2 and 4 cannot be checked (but group 1 is 'ok'.) Likewise, if anything in 4 is checked, then 2 and 3 cannot... (but again, group 1 would be 'ok'.)

screenshot to (hopefully) allow it to make sense:

f53ia9.jpg


So, would something like that require a major overhaul to what we have thus far, or could it be implemented (somewhat?) easily?
(again, I'm just fine with this if its a PITA... just don't reply back to this thread and block me. ) (lol, j/k about the blocking part :laugh: but I really do appreciate all your help and work with what you've done so far. )
 
Upvote 0
some FWIW just in case you're curious as to what and why i am (trying) to do here... here is why:
I have code from my other main spreadsheet I use at my work here that I realized will work perfectly for this application.

the what:
I'm going to use what is checked in the checkboxes to insert into 1 cell in a column a 'code' that is to represent that particular attribute that was checked. All of this will be going into one column, and I have to (I want to) keep separate the chkCSR, chkSEAI and chkMISC choices that are selected. (so no chkCSR choices will be in the chkSEAI choices...)
This will make it a snap for when I go to filter the data on the worksheet to show just (for example) the CSR issues (and without the other ones populating that particular cell.)

Here is what I have that is very similar in my other main workbook and the code that i use there to insert a 'code' that represents what is checked.

my userform from the other workbook i use at my work:
4sy9vk.jpg


The code from my other workbook that I use that I will make work for this application that you have helped me with...
icon14.png


Code:
If chkDeptPr.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Pr " & vbCrLf
If chkDeptPrJM.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "PrJM " & vbCrLf
If chkDeptPrTM.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "PrTM " & vbCrLf
If chkDeptPo.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Po " & vbCrLf
If chkDeptBl.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Bl " & vbCrLf
If chkDeptB8.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "B8 " & vbCrLf
If chkDeptOf.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Of " & vbCrLf
If chkDeptOfFL.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "OfFL " & vbCrLf
If chkDeptLa.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "La " & vbCrLf
If chkDeptSh.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Sh " & vbCrLf
If chkDeptMa.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Ma " & vbCrLf
If chkDeptQC.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "QC " & vbCrLf
If chkDeptSu.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Su " & vbCrLf
If chkDeptSa.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Sa " & vbCrLf
If chkDeptPu.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Pu " & vbCrLf
If chkDeptPu1.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Pu1 " & vbCrLf
If chkDeptAc.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Ac " & vbCrLf
If chkDeptCs.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Cs " & vbCrLf
If chkDeptMg.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Mg " & vbCrLf
If chkDeptHr.Value Then Cells(3, lCol + 1) = Cells(3, lCol + 1) & "Hr " & vbCrLf
 
Last edited:
Upvote 0
If anything in group 2 is checked... which means by default that the very top box (which is the chkCSR box for group 2) then no boxes in group 3 or 4 can be checked. BUT... group 1 still could be... (or, maybe not... group 1 is to be optional and independent of what happens in groups 2-4.)

The same is going to be true for the other 2 groups (groups 3 and groups 4)... If anything is checked in 3, then 2 and 4 cannot be checked (but group 1 is 'ok'.) Likewise, if anything in 4 is checked, then 2 and 3 cannot... (but again, group 1 would be 'ok'.)


This is like math, first they teach you the whole procedure and then they teach you the formula to make it shorter.

I put the code reduced with a class. Change all your code for the following to validate all the checkboxes of the 4 groups.

----------
Create a class module and put the following.
Change UserForm3 to the name of your userform

Code:
Public WithEvents chbCustom1 As MSForms.CheckBox 'Custom checkbox


Private Sub chbCustom1_Click()
    Call [COLOR=#ff0000]UserForm3[/COLOR].check_groups(chbCustom1)
End Sub

--------
In the userform code:

Code:
Dim colCheck As Collection 'Collection of checks
Public loading As Boolean
Public pr1 As Boolean, pr2 As Boolean, pr3 As Boolean, pr4 As Boolean


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
            Set clsObject = New Class1
            Set clsObject.chbCustom1 = ctlLoop
            colCheck.Add clsObject
        End If
    Next ctlLoop
    loading = False
'end Load


End Sub


Sub check_groups(chbCustom1 As MSForms.CheckBox)
    Dim grupo As String, checkG As MSForms.CheckBox
    Dim n As Long, chk As Control, salir As Boolean


    If loading Then Exit Sub
    loading = True
    
    grupo = Left(chbCustom1.Name, 6)
    
    Select Case grupo
        Case "chkEHS": Set checkG = chkEHS
        Case "chkCSR"
            Set checkG = chkCSR
            If pr3 Or pr4 Then salir = True Else pr2 = True
        Case "chkSEA"
            Set checkG = chkSEAI
            If pr2 Or pr4 Then salir = True Else pr3 = True
        Case "chkMIS"
            Set checkG = chkMISC
            If pr2 Or pr3 Then salir = True Else pr4 = True
    End Select
    
    If salir Then
        MsgBox "[COLOR=#ff0000]No Checkboxes can be checked in this Group[/COLOR]", vbExclamation
        chbCustom1 = False
    Else
        n = 0
        For Each chk In Me.Controls
            If TypeName(chk) = "CheckBox" Then
                If Left(chk.Name, 6) = grupo And chk.Name <> checkG.Name And _
                   chk.Value = True Then
                    n = n + 1
                    If n = 3 Then
                        MsgBox "[COLOR=#ff0000]Maximum allowed 2[/COLOR]"
                        chbCustom1 = False
                    End If
                    checkG = True
                End If
            End If
        Next
        If n = 0 Then
            checkG = False
            Select Case checkG.Name
                Case "chkCSR": pr2 = False
                Case "chkSEAI": pr3 = False
                Case "chkMISC": pr4 = False
            End Select
        End If
    End If
    loading = False
End Sub

---------
In the class module, All the checkboxes are processed, any checkbox with click enters the class module, the class calls the procedure "check_groups" and then the chceck data is verified: the group, the value, how many check per group and if it can or it can not be activated.

You only have to keep this nomenclature for checkboxes:

Groups
"chkEHS"
"chkCSR"
"chkSEAI"
"chkMISC"

Checks:
"chkEHS_any"
"chkCSR_any"
"chkSEA_any"
"chkMIS_any"
 
Upvote 0
This is like math, first they teach you the whole procedure and then they teach you the formula to make it shorter.

Well thank you for helping me learn... which you have alot within this thread and my checkbox request!
icon14.png


I put the code reduced with a class. Change all your code for the following to validate all the checkboxes of the 4 groups.

----------
Create a class module and put the following.
Change UserForm3 to the name of your userform

Code:
Public WithEvents chbCustom1 As MSForms.CheckBox 'Custom checkbox


Private Sub chbCustom1_Click()
    Call [COLOR=#ff0000]UserForm3[/COLOR].check_groups(chbCustom1)
End Sub

Sorry for the delay in my response... I havent had the time today to play around with my workbook. BUT... when I finally did I had some issues with getting it to finally work correctly for me. NOT because of your code, but I had to make it work within all my other existing code in this workbook. The main issue I had I finally figured out by sheer luck... I cut this part of the code from where it was and put it as the very first bit of code in the VBA.

--------
In the userform code:

Code:
Dim colCheck As Collection 'Collection of checks
Public loading As Boolean
Public pr1 As Boolean, pr2 As Boolean, pr3 As Boolean, pr4 As Boolean

Anywhere else and it wouldn't work. (it wouldn't give me any errors or trip up, it just ignored everything where it should of been giving me the messages like 'maxiumum of 2 allowed' and 'not choosing boxes in the other groups' (plus it would allow me to check as many checkboxes as I wanted to... ) Anyway, once i cut it and put it at the top, everything is working GREAT.

Thank you, DanteAmor. You were of great help to me, sir!
 
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