Enabling/Disabling a Checkbox Using VBA

MBCOR

New Member
Joined
Nov 24, 2015
Messages
5
Hi,

I am trying to enable or disable an ActiveX Controls CheckBox depending on whether a value in an adjacent cell is greater or less than or equal to 0. The CheckBox would be enabled if the value is greater than 0 and disabled if the value is less than or equal to 0.

I found this thread (http://www.mrexcel.com/forum/excel-questions/420586-disable-checkbox-visual-basic-applications.html) and changed the code to one that would read the value from an adjacent cell.

The code I have so far is:

Code:
Private Sub CB1_Change()
    Select Case Range("C22").Value > 0
    Case True: CB1.Enabled = True
    Case False: CB1.Enabled = False
    End Select
End Sub

The checkbox disables when I input a value less than or equal to 0 in cell C22 but when I then input a value greater than 0 into cell C22 the cell remains disabled instead of becoming enabled again. The only way for me to enable the cell again is to hit the F8 key multiple times in the VBA.

How can I get the checkbox to change from disabled to enabled based on a cell value after it has been disabled?

Thanks
 
Yup you were right my checkboxes were out of sequence. Thanks so much for the help!

One last question: If I need to add rows at the bottom do I just increase the range as needed?
You are welcome.

If you add rows just change C137 to the last cell address.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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