Stopping a Checked Box from being Unchecked

by Allen Wyatt
(last updated January 2, 2016)

4

Noel created a form that includes some check boxes. When someone selects the check box (so that a check appears in it), he would like to "lock" it so that the check box cannot then be unchecked.

This is very easy to do if you are using ActiveX check boxes in your form. All you need to do is remember that when the check box is clicked, an event is triggered for that checkbox. Let's say that your checkbox has a default name, such as CheckBox1. In this case, the CheckBox1_Click() event is triggered. Within the event handler, you can do just about anything you desire, including making sure that the check box stays checked.

Private Sub CheckBox1_Click()
    MsgBox "ActiveX CheckBox1 Clicked"
    If CheckBox1.Value = False Then CheckBox1.Value = True
End Sub

This approach works because the Value property of the check box is toggled whenever the check box is clicked. If it toggles to False (which means it is no longer checked), then you can immediately set the Value property back to True (meaning it is checked). This could be simplified a bit in this manner:

Private Sub CheckBox1_Click()
    MsgBox "ActiveX CheckBox1 Clicked"
    If Not (CheckBox1) Then CheckBox1 = 1
End Sub

In fact, you could simplify it even further in this way:

Private Sub CheckBox1_Click()
    MsgBox "ActiveX CheckBox1 Clicked"
    CheckBox1 = True
End Sub

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13415) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Chapter Numbers in Indexes and TOAs

Word allows you to define prefixes for page numbers. These are often used for chapter or section numbers in a large document. ...

Discover More

Selective Undo

Ever wonder why you can't undo just a single edit you made a few minutes earlier? The short answer is that it could make your ...

Discover More

Viewing a Revision History for a Document

Need to know how a document has evolved over time? Docs has your document's history available at all times. How you access ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Relative References when Recording Macros

When you record a macro, make sure that you know how Excel is recording your cell movements. This tip explains the problem ...

Discover More

Adjusting a Path Based on System and User

It is not uncommon to set variables in a macro based on other values, such as time or date. You could also set variables ...

Discover More

Opening a Workbook but Disabling Macros

Macros that run automatically when you open or close a workbook are quite helpful. You may not want them to run, however, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 4?

2016-01-03 07:29:52

Les

Perhaps you mistake my comment. I mean that locking the user into a response in this way is poor practice, and should not be done!


2016-01-02 12:30:46

Robert C

Dave, undo does not work for changes done by VBA macros.
Les, the user would need to know how to stop the VBA macro execution and then bypass the resetting of the box checking.
You gain control of the VBA macro execution by pressing Ctrl-pause and then step in bypassing the checking done by the macro.
You can also open the VBA macro editor and set debug on the box checking, then you can bypass it when it gets to that step.


2016-01-02 10:27:18

Dave H.

Les - Good point. Would "Edit->Undo"(Ctrl-Z) work? The only other workaround would be to close the workbook without saving changes. This would be very cumbersome especially since you would then have to start from scratch after re-opening. Perhaps someone has a better solution...


2016-01-02 05:00:29

Les

I don't think that it is a very good idea to prevent unchecking - how does the user correct after initially checking the box in error?


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.