Home > Net >  Change cell text and other checkbox based on another checkbox
Change cell text and other checkbox based on another checkbox

Time:06-28

I am trying to figure out following conditions via excel checkbox click (Refer the images attached) enter image description here enter image description here

After researching over Google, I am able to check and uncheck all sub-chckeboxes of cbx_1 via below code (Edited after commet of @user123677) -

Sub cbxGrp_Click()
    Dim oCbx As CheckBox
    Dim lValue As Long
    Dim sGrp As String
    sGrp = Application.Caller
    lValue = ActiveSheet.CheckBoxes(sGrp).Value
    sGrp = Split(sGrp, "_")(1)
    For Each oCbx In ActiveSheet.CheckBoxes
        If oCbx.Name Like "cbx_" & sGrp & "_*" Then
            oCbx.Value = lValue
        End If
    Next
    
    If lValue <> 1 Then
        Range("b2").Value = CVErr(xlErrNA)
        Range("B3").Value = False
        Range("B5").Value = False
        Range("B6").Value = False
    
    End If
    
End Sub

Now requirement is -

If I uncheck cbx_1_1 -

  1. B2 = #N/A
  2. B3, B5, B6 = FALSE
  3. Rest will remain same
  4. cbx_1_1_1 & cbx_1_1_2 checkboxes should be unchecked

Same logic for checkbox cbx_1_2. I am not very familiar with VBA scripting, so any help would be appreciated.

I have also uploaded the excel file here to check directly.

CodePudding user response:

you could add this to your code

Edit: after comment from @Pᴇʜ, thanks

If lValue <> 1 Then
    Range("b2").Value = CVErr(xlErrNA)
    Range("b3").Value = False
    Range("b5").Value = False
    Range("b6").Value = False
    
End If

I haven't checked your code or made this the most efficient but for normal use this should be fine.

let me know how you get on :)

  • Related