Kamis, 11 Oktober 2012

description and examples of data validation in Excel

Description and examples of data validation in Excel

Article ID: 211485 - View products that this article applies to.
This article was previously published under Q211485
For a Microsoft Excel 97 version of this article, see 159252
.
For a Microsoft Excel 98 Macintosh Edition version of this article, see 181323
.

On This Page


SUMMARY

Data validation is a feature available in Microsoft Excel. 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 data validation feature in Microsoft Excel as well as examples to illustrate how to implement this feature.

NOTE: The examples below assume you are working with a new Microsoft Excel 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, follow these steps:

  1. Select cell A1.
  2. On the Data menu, click Validation.
  3. On the Settings tab, click List in the Allow drop-down list.
  4. By default, the Ignore blank and In-cell Dropdown check boxes are selected. Do not change them.
  5. In the Source box, type a,b,c. Click OK.

    NOTES:
    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.
    There is a 255 character limitation for this dialog.
  6. 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.
  7. 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 ESC. If the Office Assistant is visible, the message appears in a balloon above the Office Assistant.

Continuing with the previous example, follow these steps:
  1. Select cell A1.
  2. 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.
  3. In the Title box, type List for cell A1.

    This is the title for the message box that appears. It is in bold text.
  4. In the Input message box, type Please select either a, b or c from the drop-down list.

    This is the body of the message that appears.
  5. Click OK.

    The message appears because cell A1 is selected.
  6. Select cell A10.

    The drop-down list next to cell A1 and the message for cell A1 both disappear.
  7. 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.
  8. 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 enter out-of-range data, or you can set limits on the data but not display any messages.

Continuing with the previous example, follow these steps:
  1. Select cell A1.
  2. 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.

    1. In the Style list, click Stop.
    2. In the Title box, type Warning for cell A1. This is the title for the message box that appears.
    3. In the Error Message edit box, enter The only allowable values for cell A1 are a, b, or c. This is the body of the message that appears and is limited to 225 characters.
    4. Click OK.
  3. Manually enter t, in cell A1.

    The Stop Alert message you created appears and your only options are Retry or Cancel.
  4. Click Cancel on the Stop Alert message box.
  5. Select cell A1.
  6. 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.

    1. In the Style list, click Warning.
    2. In the Title box, type Warning for cell A1. This is the title for the message box that appears.
    3. In the Error message box, type The only allowable values for cell A1 are a, b, or c. This is the body of the message that appears and is limited to 225 characters.
    4. Click OK.
  7. Manually enter j in cell A1.

    The Warning message you created appears asking if you want to Continue.
  8. Click Yes.

    The invalid value of "j" is entered in cell A1.
  9. Select cell A1.
  10. 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.

    1. In the Style list, click Information.
    2. In the Title box, type Warning for cell A1. This is the title for the message box that appears.
    3. In the Error message box, type The only allowable value for cell A1 are a, b, or c. This is the body of the message that appears and is limited to 225 characters.
    4. Click OK.
  11. Manually enter p in cell A1.

    The Information Alert message you created appears asking if you want to accept or reject the value you entered.
  12. 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, follow these steps:

  1. On the Tools menu, click Customize.
  2. In the Customize dialog box, click the Toolbars tab.
  3. In the Toolbars list, click to select the Auditing check box (if it's not already selected) and then click Close.
  4. On the Auditing toolbar, click the Circle Invalid Data control. Cell A1 is circled.
  5. Select cell A1.
  6. 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.

  1. Select cell A5.
  2. On the Data menu, click Validation and click the Settings tab.
  3. In the Allow list, click Whole number.
  4. In the Data list, click between.
  5. In the Minimum box, enter 1.
  6. 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.
  7. Click OK.
  8. Enter the value 3 in cell A5. The value is entered without error.
  9. Enter the value 33 in cell A5.

    Because 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.
  10. 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.
  1. Enter the value 1 in cell B10.
  2. Select cell A10.
  3. On the Data menu, click Validation and click the Settings tab.
  4. In the Allow list, click Custom.
  5. 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.
  6. Click OK.
  7. Enter the value -1 in cell A10.

    You receive a Stop Alert message stating the value is invalid.
  8. Click Retry.
  9. 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.

Tidak ada komentar:

Posting Komentar