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.

Data validation

Apply data validation to cells

You use data validation to control the type of data or the values that users enter into a cell. For example, you may want to restrict data entry to a certain range of dates, limit choices by using a list, or make sure that only positive whole numbers are entered.
This article describes how data validation works in Excel and outlines the different data validation techniques available to you. It does not cover cell protection, which is a feature that lets you "lock" or hide certain cells in a worksheet so that they can't be edited or overwritten. For more information about how to protect cells, see the links in the See Also section.
In this article


What is data validation?

Data validation is an Excel feature that you can use to define restrictions on what data can or should be entered in a cell. You can configure data validation to prevent users from entering data that is not valid. If you prefer, you can allow users to enter invalid data but warn them when they try to type it in the cell. You can also provide messages to define what input you expect for the cell, and instructions to help users correct any errors.
For example, in a marketing workbook, you can set up a cell to allow only account numbers that are exactly three characters long. When users select the cell, you can show them a message such as this one:
Selected cell and input message
If users ignore this message and type invalid data in the cell, such as a two-digit or five-digit number, you can show them an actual error message.
In a slightly more advanced scenario, you might use data validation to calculate the maximum allowed value in a cell based on a value elsewhere in the workbook. In the following example, the user has typed $4,000 in cell E7, which exceeds the maximum limit specified for commissions and bonuses.
Invalid data and warning message
If the payroll budget were to increase or decrease, the allowed maximum in E7 would automatically increase or decrease with it.
Data validation options are located in the Data Tools group.
Excel Ribbon Image
You configure data validation in the Data Validation dialog box.
Data Validation dialog box
Top of Page Top of Page

When is data validation useful?

Data validation is invaluable when you want to share a workbook with others in your organization, and you want the data entered in the workbook to be accurate and consistent.
Among other things, you can use data validation to do the following:
  • Restrict data to predefined items in a list    For example, you can limit types of departments to Sales, Finance, R&D, and IT. Similarly, you can create a list of values from a range of cells elsewhere in the worksheet. For more information, see Create a drop-down list from a range of cells.
Drop-down list created by using data validation
  • Restrict numbers outside a specified range    For example, you can specify a minimum limit of deductions to two times the number of children in a particular cell.
  • Restrict dates outside a certain time frame    For example, you can specify a time frame between today's date and 3 days from today's date.
  • Restrict times outside a certain time frame     For example, you can specify a time frame for serving breakfast between the time when the restaurant opens and 5 hours after the restaurant opens.
  • Limit the number of text characters    For example, you can limit the allowed text in a cell to 10 or fewer characters. Similarly, you can set the specific length for a full name field (C1) to be the current length of a first name field (A1) and a last name field (B1), plus 10 characters.
  • Validate data based on formulas or values in other cells    For example, you can use data validation to set a maximum limit for commissions and bonuses of $3,600, based on the overall projected payroll value. If users enter more than $3,600 in the cell, they see a validation message.
Top of Page Top of Page

Data validation messages

What users see when they enter invalid data into a cell depends on how you have configured the data validation. You can choose to show an input message when the user selects the cell. This type of message appears near the cell. You can move this message, if you want to, and it remains until you move to another cell or press ESC.
Input message
Input messages are generally used to offer users guidance about the type of data that you want entered in the cell.
You can also choose to show an error alert that appears only after users enter invalid data.
Error alert with custom warning message
You can choose from three types of error alerts:
Icon Type Use to
Stop icon Stop Prevent users from entering invalid data in a cell. A Stop alert message has two options: Retry or Cancel.
Warning icon Warning Warn users that the data they entered is invalid, without preventing them from entering it. When a Warning alert message appears, users can click Yes to accept the invalid entry, No to edit the invalid entry, or Cancel to remove the invalid entry.
Information icon Information Inform users that the data they entered is invalid, without preventing them from entering it. This type of error alert is the most flexible. When an Information alert message appears, users can click OK to accept the invalid value or Cancel to reject it.
You can customize the text that users see in an error alert message. If you choose not to do so, users see a default message.
Input messages and error alerts appear only when data is typed directly into the cells. They do not appear under the following conditions:
Top of Page Top of Page

How to handle a data validation alert

When you try to enter or change data in a worksheet (worksheet: The primary document that you use in Excel to store and work with data. Also called a spreadsheet. A worksheet consists of cells that are organized into columns and rows; a worksheet is always stored in a workbook.) cell, you see a data validation error alert. This alert signifies that the owner of the workbook applied data validation (data validation: An Excel feature that you can use to define restrictions on what data can or should be entered in a cell, and to display messages that prompt users for correct entries and notify users about incorrect entries.) to the cell to prevent users from entering invalid data, and implemented the error alert to let you know that the data you entered is invalid.
You can enter only valid data in cells that have data validation applied. If you are not clear about the validity of the data that you can enter, you should contact the owner of the workbook.
If you inherited the workbook, you can modify or remove the data validation unless the worksheet is protected with a password that you do not know. If possible, you can contact the previous owner to help you unprotect the worksheet. You can also copy the data to another worksheet, and then remove the data validation. For more information about how to change or remove data validation, see Change data validation settings or Remove data validation.

Tips for working with data validation

In the following list, you will find tips and tricks for working with data validation in Excel.
  • If you plan to protect (protect: To make settings for a worksheet or workbook that prevent users from viewing or gaining access to the specified worksheet or workbook elements.) the worksheet or workbook, protect it after you have finished specifying any validation settings. Make sure that you unlock any validated cells before you protect the worksheet. Otherwise, users will not be able to type any data in the cells.
  • If you plan to share the workbook, share it only after you have finished specifying data validation and protection settings. After you share a workbook, you won't be able to change the validation settings unless you stop sharing, but Excel will continue to validate the cells that you have designated while the workbook is being shared.
  • You can apply data validation to cells that already have data entered in them. However, Excel does not automatically notify you that the existing cells contain invalid data. In this scenario, you can highlight invalid data by instructing Excel to circle it on the worksheet. Once you have identified the invalid data, you can hide the circles again. If you correct an invalid entry, the circle disappears automatically.
Red circle around invalid data
  • To quickly remove data validation for a cell, select it, and then open the Data Validation dialog box (Data tab, Data Tools group). On the Settings tab, click Clear All.
  • To find the cells on the worksheet that have data validation, on the Home tab, in the Editing group, click Find & Select, and then click Data Validation. After you have found the cells that have data validation, you can change, copy, or remove validation settings.
  • When creating a drop-down list, you can use the Define Name command (Formulas tab, Defined Names group) to define a name for the range that contains the list. After you create the list on another worksheet, you can hide the worksheet that contains the list and then protect the workbook so that users won't have access to the list.
If data validation isn't working, make sure that:
Users are not copying or filling data     Data validation is designed to show messages and prevent invalid entries only when users type data directly in a cell. When data is copied or filled, the messages do not appear. To prevent users from copying and filling data by dragging and dropping cells, clear the Enable fill handle and cell drag-and-drop check box (Excel Options dialog box, Advanced options), and then protect the worksheet.
Manual recalculation is turned off     If manual recalculation is turned on, uncalculated cells can prevent data from being validated correctly. To turn off manual recalculation, on the Formulas tab, in the Calculation group, click Calculation Options, and then click Automatic.
Formulas are error free     Make sure that formulas in validated cells do not cause errors, such as #REF! or #DIV/0!. Excel ignores the data validation until you correct the error.
Cells referenced in formulas are correct     If a referenced cell changes so that a formula in a validated cell calculates an invalid result, the validation message for the cell won't appear.
Top of Page Top of Page

Add data validation to a cell or range

In the next sections, you will learn the different techniques for adding validation to cells in a worksheet.


Restrict data entry to values in a drop-down list

It is not possible to change the font or font size for items in a list.
  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table might be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You might currently be entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering data, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select List.
  2. Click the Source box and then type the list values separated by the Microsoft Windows list separator character (commas by default).
    1. For example:
  • To limit entry to a question, such as "Do you have children?", to two choices, type Yes, No.
  • To limit a vendor's quality reputation to three ratings, type Low, Average, High.
    1. You can also create the list entries by referring to a range of cells elsewhere in the workbook. For more information, see Create a drop-down list from a range of cells.
    2.  Note   The width of the drop-down list is determined by the width of the cell that has the data validation. You might need to adjust the width of that cell to prevent truncating the width of valid entries that are wider than the width of the drop-down list.
  1. Make sure that the In-cell dropdown check box is selected. Otherwise, you won't be able to see the drop-down arrow next to the cell.
  2. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    1.  Note   If your allowed values are based on a cell range that has a defined name and there is a blank cell anywhere in that range, selecting the Ignore blank check box allows any value to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, selecting the Ignore blank check box allows any value to be entered in the validated cell.
  3. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  • Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  •  Note   If you want to allow users to type entries that are not in the list, clear the Show error alert after invalid data is entered check box instead.
  • Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  • Fill in the title and text for the message (up to 225 characters).
    1.  Note   If you don't enter a title or text, the title uses the default string "Microsoft Excel" and the message is (by default): "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Restrict data entry to a whole number within limits

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Whole number.
  2. In the Data box, select the type of restriction that you want. For example, to set upper and lower limits, select between.
  3. Enter the minimum, maximum, or specific value to allow. You can also enter a formula that returns a number value.
    1. For example, to set a minimum limit of deductions to two times the number of children in cell F1, select greater than or equal to in the Data box and enter the formula, =2*F1, in the Minimum box.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    1.  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  • Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  • Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  • Fill in the title and text for the message (up to 225 characters).
  •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Restrict data entry to a decimal number within limits

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  1. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Decimal.
  2. In the Data box, select the type of restriction that you want. For example, to set upper and lower limits, select between.
  3. Enter the minimum, maximum, or specific value to allow. You can also enter a formula that returns a number value.
    1. For example, to set a maximum limit for commissions and bonuses of 6% of a salesperson's salary in cell E1, select less than or equal to in the Data box and enter the formula, =E1*6%, in the Maximum box.
      •  Note   To let a user enter percentages, for example 20%, select Decimal in the Allow box, select the type of restriction that you want in the Data box, enter the minimum, maximum, or specific value as a decimal, for example .2, and then display the data validation cell as a percentage by selecting the cell and clicking Percent Style Button image in the Number group on the Home tab.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    1.  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Restrict data entry to a date within a time frame

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Date.
  2. In the Data box, select the type of restriction that you want. For example, to allow dates after a certain day, select greater than.
  3. Enter the start, end, or specific date to allow. You can also enter a formula that returns a date.
    1. For example, to set a time frame between today's date and 3 days from today's date, select between in the Data box, enter =TODAY() in the Minimum box, and enter =TODAY()+3 in the Maximum box.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    1.  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Restrict data entry to a time within a time frame

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Time.
  2. In the Data box, select the type of restriction that you want. For example, to allow times before a certain time of day, select less than.
  3. Enter the start, end, or specific time to allow. You can also enter a formula that returns a time.
    • For example, to set a time frame for serving breakfast between the time when the restaurant opens (the value in cell H1) and five hours after that, select between in the Data box, enter =H1 in the Minimum box, and then enter =H1+"5:00" in the Maximum box.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    •  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Restrict data entry to text of a specified length

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Text Length.
  2. In the Data box, select the type of restriction that you want. For example, to allow up to a certain number of characters, select less than or equal to.
  3. Enter the minimum, maximum, or specific length for the text. You can also enter a formula that returns a number value.
    • For example, to set the specific length for a full name field (C1) to be the current length of a first name field (A1) and a last name field (B1) plus 10, select less than or equal to in the Data box and enter =SUM(LEN(A1),LEN(B1),10) in the Maximum box.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    •  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Calculate what is allowed based on the content of another cell

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select the type of data that you want.
  2. In the Data box, select the type of restriction that you want.
  3. In the box or boxes below the Data box, click the cell that you want to use to specify what is allowed.
    • For example, to allow entries for an account only if the result won't go over the budget in cell E4, select Decimal for Allow, select less than or equal to for Data, and in the Maximum box, enter =E4.
  4. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    •  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  5. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    • To display an information message that does not prevent entry of invalid data, select Information.
    • To display a warning message that does not prevent entry of invalid data, select Warning.
    • To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.

Use a formula to calculate what is allowed

  1. Select one or more cells to validate.
  1. On the Data tab, in the Data Tools group, click Data Validation.
  1. Excel Ribbon Image
  2. ShowIssue: The Data Validation command is unavailable.
  1. An Excel table may be linked to a SharePoint site     You cannot add data validation to an Excel table that is linked to a SharePoint site. To add data validation, you must unlink the Excel table or convert the Excel table to a range.
  2. You may be currently entering data     The Data Validation command is not available on the Data tab while you are entering data in a cell. To finish entering, press ENTER or ESC.
  3. The worksheet might be protected or shared     You cannot change data validation settings if your workbook is shared or protected. To learn how to stop sharing or protecting a workbook, see the links in the See Also section.
  1. In the Data Validation dialog box, click the Settings tab.
  1. In the Allow box, select Custom.
  2. In the Formula box, enter a formula that calculates a logical value (TRUE for valid or FALSE for invalid entries). For example:
  1. To make sure that
  1. Enter this formula
  1. The cell for the picnic account (B1) can only be updated if nothing is budgeted for the discretionary account (D1) and the total budget (D2) is less than the $40,000 allocated.
  1. =AND(D1=0,D2<40000)
  1. The cell that contains a product description (B2) only contains text.
  1. =ISTEXT(B2)
  1. For the cell that contains a projected advertising budget (B3), the subtotal for subcontractors and services (E1) must be less than or equal to $800, and the total budget amount (E2) must also be less than or equal to $97,000.
  1. =AND(E1<=800,E2<=97000)
  1. The cell that contains an employee age (B4) is always greater than the number of full years of employment (F1) plus 18 (the minimum age of employment).
  1. =IF(B4>F1+18,TRUE,FALSE)
  1. All the data in the cell range A1:A20 contains unique values.
  1. =COUNTIF($A$1:$A$20,A1)=1
  2. You must enter the formula in the data validation for cell A1, and then fill the cells A2 though A20 so that the data validation for each cell in the range has a similar formula, but the second argument to the COUNTIF will match the current cell.
  1. The cell that contains a product code name (B5) always begins with the standard prefix of ID- and is at least 10 characters long.
  1. =AND(LEFT(B5, 3) ="ID-",LEN(B5) > 9)
  1. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.
    •  Note   If your allowed values are based on a cell range with a defined name, and there is a blank cell anywhere in the range, setting the Ignore blank check box allows any values to be entered in the validated cell. This is also true for any cells that are referenced by validation formulas: if any referenced cell is blank, setting the Ignore blank check box allows any values to be entered in the validated cell.
  2. Optionally, display an input message when the cell is clicked.
    1. ShowHow to display an input message
  1. Click the Input Message tab.
  2. Make sure the Show input message when cell is selected check box is selected.
  3. Fill in the title and text for the message.
  1. Specify how you want Microsoft Office Excel to respond when invalid data is entered.
    1. ShowHow to specify a response to invalid data
  1. Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
  2. Select one of the following options for the Style box:
    1. To display an information message that does not prevent entry of invalid data, select Information.
    2. To display a warning message that does not prevent entry of invalid data, select Warning.
    3. To prevent entry of invalid data, select Stop.
  3. Fill in the title and text for the message (up to 225 characters).
    •  Note   If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
  1. Test the data validation to make sure that it is working correctly.
Try entering both valid and invalid data in the cells to make sure that your settings are working as you intended and your messages are appearing when you expect.
Tip    If you change the validation settings for a cell, you can automatically apply your changes to all other cells that have the same settings. To do so, open the Data Validation dialog box, and then select the Apply these changes to all other cells with the same settings check box on the Settings tab.