Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
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.
Learn more about Allen...
Merle is trying to use the Data Validation feature of Excel to limit what a user can choose in a cell. When the user activates a cell he only wants an answer of Yes, No, or N/A; he does not want the user to be able to get out of the cell and leave it blank (empty). Merle has set up a list for the acceptable values (Yes, No, and N/A) and has unchecked the Ignore Blanks check box when setting up the Data Validation.
The problem is that when someone activates the cell, it is possible for them to still leave it empty. The only time that Excel won't allow the person to leave the cell blank is if they start to edit the cell and try to leave it blank after the edit. Merle wants, once the cell is selected, for the user to absolutely only be able to leave the cell if they choose Yes, No, or N/A.
Data Validation, by itself, can't take care of this. There are a couple of ways that you can work around the problem, however. The first idea is to modify the options that you give the user. For instance, let's say that you add a fourth choice of "Provide Answer." You could then change the value in the cell to the same value and save your workbook. When the user opens it, the cell contains "Provide Answer" and, once they select the cell, they won't be able to blank it out; they will need to provide an answer.
Another option is to use a macro in conjunction with the Data Validation you have set up. The easiest method is to set up an event handler for each time the selection changes in the worksheet. The following example kicks into play if the cell selection is C22 (which is where your Data Validation should be, as well).
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim rng As Range Set rng = Range("C22") If Application.Intersect(Target, rng) Is Nothing Then MsgBox "You must select the answer from the list" End If End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8767) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!