XL: Verifying the Value of a Check BoxLast reviewed: February 3, 1998Article ID: Q109418 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, check boxes can have one of three values: xlOn, xlOff, or xlMixed. To find the value of a check box, you can use Microsoft Visual Basic for Basic Applications code. (An example of how to do this is shown in the "More Information" section of this article.) Or, if the check box has been linked to a cell, you can use Visual Basic commands to determine the value of that cell.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.aspIf a check box is linked to a cell on a worksheet, the cell will display one of three different values:
Value Check Box Status ------------------------ TRUE Selected (On) FALSE Cleared (Off) #N/A MixedTo examine the value of the check box, examine the value of the cell to which it has been linked. To link a check box to a cell on a worksheet:
Sample Visual Basic ProcedureThe following example assumes that you have a dialog sheet (Dialog1) that contains one or more check boxes and is located in the same workbook as the Visual Basic module. It checks the value of the check boxes, regardless of whether they have been linked to cells. To run the example, position the insertion point in the line that reads "Sub ExamineCheckBoxes()" and either press the F5 key or click Start on the Run menu.
Option Explicit Sub ExamineCheckBoxes() 'Declare the variable used as the For Each loop counter Dim Box as CheckBox ' Iterate once for each check box in the dialog sheet. For Each Box in DialogSheets("Dialog1").CheckBoxes ' Get the value of the current check box. Select Case Box.Value Case xlOn ' If the check box is ON MsgBox "Check box is on!" ' show the "On" message. Case xlOff ' If the check box is OFF MsgBox "Check box is off!" ' show the "Off" message. Case xlMixed ' If the check box is MIXED MsgBox "Check box is mixed!" ' show the "Mixed" message. End Select ' Repeat the loop until finished. Next Box End SubThis subroutine will examine each check box in the dialog sheet and display its value.
|
Additional query words: 5.00 5.00a 5.00c 7.00 7.00a XL98 XL97 XL7 XL5
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |