The information in this article applies to:
- Microsoft Excel 97 for Windows
SUMMARY
Data validation is a new feature available in Microsoft Excel 97. It allows
you to do the following:
- Make a list of the entries that restricts the values allowed in a cell.
- Create a prompt message explaining the kind of data allowed in a cell.
- Create messages that appear when incorrect data has been entered.
- Check for incorrect entries by using the Auditing toolbar.
- Set a range of numeric values that can be entered in a cell.
- Determine if an entry is valid based on calculation in another cell.
MORE INFORMATION
This article describes some of the ways to use the new data validation
feature in Microsoft Excel 97 as well as examples to illustrate how to
implement this feature.
NOTE: The examples below assume you are working with a new Microsoft Excel
97 workbook and that you start with the first example and continue through
the examples in the order in which they are presented.
Make a List of Entries Allowed in the Cell
You can make a list of the entries you will accept for a cell on a
worksheet. You can then restrict the cell to accept only entries taken from
the list by using the data validation feature.
To create a drop-down list and restrict values in the cell to these
entries, do the following:
- Select cell A1.
- On the Data menu, click Validation.
- On the Settings tab, click List in the Allow drop-down list.
- By default, the Ignore Blank and In-cell Dropdown check boxes are
selected. Do not change them.
- In the Source edit box, enter "a,b,c" (without quotation marks).
NOTE: You can also enter a named range or cell reference if it contains
a list of values. Both must be preceded by an equal sign.
- Click OK.
Cell A1 now has a drop-down list next to it and you can use this list
to select the value to enter in the cell.
- Click the drop-down list and then click any item it contains.
This value will be entered in the cell.
NOTE: You can manually enter "a", "b", or "c", (without quotation marks) in
the cell; you do not have to select these from the list. If you try to
manually enter anything other these values, a stop message appears and you
are unable to keep the value in this cell. Your only options are Retry or
Cancel.
Create a Prompt Message Explaining the Type of Data Allowed in a Cell
You can create a message that explains the type of data that can be entered
in a cell. When you select the cell, the message appears near the cell. You
can move this message, if necessary, and it remains until you move to
another cell or press the Escape key. If the Office Assistant is visible,
the message appears in a balloon above the Office Assistant.
Continuing with the previous example, do the following:
- Select cell A1.
- On the Data menu, click Validation and then click the Input Message tab.
NOTE: Make sure the "Show input message when cell is selected" check
box is selected.
- In the Title edit box, enter "List for cell A1" (without quotation
marks).
This is the title for the message box that appears. It is in
bold text.
- In the Input Message edit box, enter "Please select either a, b or c
from the drop-down list" (without quotation marks).
This is the body of the message that appears.
- Click OK.
The message appears because cell A1 is selected.
- Select cell A10.
The drop-down list next to cell A1 and the message for cell A1 both
disappear.
- Select cell A1.
Both the drop-down list and the prompt message appear next to cell A1.
NOTE: If the Office Assistant is visible, the prompt message appears
in a balloon above the Office Assistant.
- Move the message to another location in the worksheet.
When you select another cell and then select cell A1 again, the message
appears in its new location.
NOTE: There is no way to change the formatting for this message.
Create a Message That Appears When Incorrect Data is Entered
The style of the error message Microsoft Excel displays when you type
incorrect data determines whether the restrictions are enforced. You can
display a message that stops you from entering data values except those
specified. You can also display explanatory and warning messages that let
you to enter out-of-range data, or you can set limits on the data but not
display any messages.
Continuing with the previous example, do the following:
- Select cell A1.
- On the Data menu, click Validation and then click the Error Alert tab.
NOTE: Make sure the "Show error alert after invalid data is entered"
check box is selected.
Create a Stop Alert Message
---------------------------
If you create a Stop Alert message and enter invalid data in the cell,
your only options are Retry or Cancel; you are Not allowed to enter
invalid data in the cell.
a. In the Style list, click Stop.
b. In the Title edit box, enter "Warning for cell A1" (without
quotation marks). This is the title for the message box that
appears.
c. In the Error Message edit box, enter "The only allowable values for
cell A1 are a, b, or c", (without quotation marks). This is the body
of the message that appears and is limited to 225 characters.
d. Click OK.
- Manually enter "t" (without quotation marks), in cell A1.
The Stop Alert message you created appears and your only options are
Retry or Cancel.
- Click Cancel on the Stop Alert message box.
- Select cell A1.
- On the Data menu, click Validation and then click the Error Alert tab.
NOTE: Make sure the "Show error alert after invalid data is entered"
check box is selected.
Create a Warning Alert Message
------------------------------
If you create a Warning message and enter invalid data in the cell,
your options are a little more flexible than for a Stop Alert message.
A Warning Alert message has three options: Yes, to allow entry of the
invalid data; No, to give you a chance to enter valid data; and Cancel,
to remove the invalid entry.
a. In the Style list, click Warning.
b. In the Title edit box, enter "Warning for cell A1" (without
quotation marks). This is the title for the message box that
appears.
c. In the Error Message edit box, enter "The only allowable values for
cell A1 are a, b, or c" (without quotation marks). This is the body
of the message that appears and is limited to 225 characters.
d. Click OK.
- Manually enter "j" (without quotation marks) in cell A1.
The Warning message you created appears asking if you want to Continue.
- Click Yes.
The invalid value of "j" is entered in cell A1.
- Select cell A1.
- On the Data menu, click Validation and then click the Error Alert tab.
NOTE: Make sure the "Show error alert after invalid data is entered"
check box is selected.
Create an Information Alert Message
-----------------------------------
If you create an Information message and enter invalid data in the
cell, your options are the most flexible. When an Information Alert
message appears, you can click OK to accept the invalid value or you
can click Cancel to reject it.
a. In the Style list, click Information.
b. In the Title edit box, enter "Warning for cell A1", (without
quotation marks). This is the title for the message box that
appears.
c. In the "Error message" edit box, enter "The only allowable value for
cell A1 are a, b, or c" (without quotation marks). This is the body
of the message that appears and is limited to 225 characters.
d. Click OK.
- Manually enter "p", (without quotation marks), in cell A1.
The Information Alert message you created appears asking if you want
to accept or reject the value you entered.
- Click OK.
The invalid value of "p" is entered in cell A1.
Check for Incorrect Entries Using the Auditing Toolbar
After your data is entered, you can look for entries that are outside the
limits you set. When you click Circle Invalid Data on the Auditing toolbar,
circles appear around cells that contain incorrect entries. If you correct
an invalid entry, the circle disappears.
Continuing with the previous example, do the following:
- On the Tools menu, click Customize.
- In the Customize dialog box, click the Toolbars tab.
- In the list of Toolbars, select the Auditing check box (if it's not
already selected) and then click Close.
- On the Auditing toolbar, click the Circle Invalid Data control. Cell
A1 is circled.
- Select cell A1.
- Click the drop-down arrow next to cell A1 and then click one of the
entries in the list. The circle disappears.
Set a Range of Numeric Values That Can Be Entered in a Cell
You can place limits on the data that can be entered in a cell, you can set
minimums and maximums or check for the effect an entry might have on
another cell.
- Select cell A5.
- On the Data menu, click Validation and click the Settings tab.
- In the Allow list, click Whole number.
- In the Data list, click between.
- In the Minimum box enter 1.
- In the Maximum box enter 10.
NOTE: You can use cell references for Steps 5 and 6 to specify cells
that contain the minimum and maximum values.
- Click OK.
- Enter the value 3 in cell A5. The value is entered without error.
- Enter the value 33 in cell A5.
Since the data validation settings you created for cell A1 (an
Information Alert) do not apply to those for cell A5, you receive a
Stop Alert message (which is the default value) and your only options
are to click Retry or Cancel.
- Click Cancel. The value of 3 appears in the cell.
Determine If Entry Is Valid Based on Calculation in Another Cell
In the data validation dialog box you can use a formula, an expression or a
reference to a calculation in another cell to determine if the entry you
make is valid.
- Enter the value 1 in cell B10.
- Select cell A10.
- On the Data menu, click Validation and click the Settings tab.
- In the Allow list, click Custom.
- In the Formula box enter the following formula:
=IF(A10>B10,TRUE,FALSE)
NOTE: The formula you enter must begin with an equal sign and it must
evaluate to either true or false. It is not limited to the IF function.
- Click OK.
- Enter the value -1 in cell A10.
You receive a Stop Alert message stating the value is invalid.
- Click Retry.
- Enter the value 3 in cell A10.
You do not receive any error message since this value is greater than
the value you entered in cell B10.
REFERENCES
For more information about data validation, click the Index tab in
Microsoft Excel 97 Help, type the following text
data validation, preventing incorrect entry
and then double-click the selected text to go to the "Prevent entry of
incorrect data in a cell" topic.
|