Written by Allen Wyatt (last updated November 4, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003
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
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8767) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
When setting up a worksheet for others to use, you might want to make some limitations on what can be entered in certain ...
Discover MoreWhen setting up Excel for data entry, you often have to be concerned with what values are acceptable. For example, if ...
Discover MoreWant to control what users put into a cell? It's easy to do using a feature called data validation, as described in this tip.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments