Excel Check Box with conditions

Mohsin110

New Member
Joined
Aug 26, 2023
Messages
23
Office Version
  1. 2021
Platform
  1. Windows
Hi, I want to use checkboxes with the following condition.

VBA Code:
'Selection Change Condition
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("Combined") > 0 Then
        CustomBox = True
    End If
End sub


VBA Code:
'CheckBox Condition
Private Sub CustomBox_Click()
    If CustomBox Then
        Range("E13") = "Combined"
    Else
        Range("E13") = ""
    End If
End Sub

and if checkbox is true then value of specific range for example "E13" should be equal to a word "Combined", which i got it successfully.
But if i uncheck the checkbox then the Worksheet Selection Change condition should not be applied and range "E13" should be empty even the " range("Combined") > 0 " hopefully i have succeeded to explain.

Please help if it's possible. check reference photo to get the idea.
 

Attachments

  • img.png
    img.png
    57.2 KB · Views: 19

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
There is a much easier way to do this without using any VBA.
For each checkbox, link it to the cell in column H where it is located. You appear to be using ActiveX checkboxes; you can go to Properties and set LinkedCell. Then the linked cells will have the value TRUE or FALSE based on whether the box is checked.
For the cells in column E use the formula
Excel Formula:
=IF(H13,"Combined","")
and fill down.

In column H you can set the font to be the same color as the background color so the user does not see the TRUE/FALSE values.
 
Upvote 0
There is a much easier way to do this without using any VBA.
For each checkbox, link it to the cell in column H where it is located. You appear to be using ActiveX checkboxes; you can go to Properties and set LinkedCell. Then the linked cells will have the value TRUE or FALSE based on whether the box is checked.
For the cells in column E use the formula
Excel Formula:
=IF(H13,"Combined","")
and fill down.

In column H you can set the font to be the same color as the background color so the user does not see the TRUE/FALSE values.
Actually check boxes are only true when range "D23" greater then 0, and after getting true if i uncheck the box "Combined" should be removed from "H13" even range "D23" is greater than 0.
 
Upvote 0
I'm not following what you mean. Check boxes are True if you check the box--not sure how D23 is involved. There was no mention of D23 in your original description. You only mentioned E13, and the method I described will work for what you described in your original post.
 
Upvote 0
I'm not following what you mean. Check boxes are True if you check the box--not sure how D23 is involved. There was no mention of D23 in your original description. You only mentioned E13, and the method I described will work for what you described in your original post.
Range "Combined" is name range of "D23" mentioned in the original post.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("Combined") > 0 Then 'if range D23 greater than 0 then checkbox is true
        CustomBox = True
    End If
End sub
 
Upvote 0
In that code, what is "CustomBox"? Why is this code run on a selection change?

I am not following your use case at all here. Please describe what happens from the user's point of view when they check boxes, when Excel should automatically check or uncheck boxes, how D23 is calculated, and how D23 affects all the checkboxes.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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