by Allen Wyatt
(last updated March 3, 2021)
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.
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!
Need to use a macro to select a specific cell in a different workbook? It's not as straightforward of a proposition as ...Discover More
VBA makes it easy to copy a worksheet from the current workbook into a brand-new workbook. You may want to delete some ...Discover More
When creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.