Sunday, August 19, 2018

Apply data validation to cells

Apply data validation to cells

You can use data validation to restrict the type of data or the values that users enter into a cell. One of the most common data validation uses is to create a drop-down list.

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Download our examples

You can download an example workbook with all of the data validation examples you'll find in this article.

  1. Select the cell(s) you want to create a rule for.

  2. Select Data >Data Validation.

           Data Validation

  3. On the Settings tab, under Allow, select an option:

    • Whole Number - to restrict the cell to accept only whole numbers.

    • Decimal - to restrict the cell to accept only decimal numbers.

    • List - to pick data from the drop-down list.

    • Date - to restrict the cell to accept only date.

    • Time - to restrict the cell to accept only time.

    • Text Length - to restrict the length of the text.

    • Custom – for custom formula.

  4.  Under Data, select a condition:

    • between

    • not between

    • equal to

    • not equal to

    • greater than

    • less than

    • greater than or equal to

    • less than or equal to

  5. On the Settings tab, under Allow, select an option:

  6. Set the other required values, based on what you chose for Allow and Data.
          For example, if you select between, then select the Minimum: and Maximum: values for the cell(s).

  7. Select the Ignore blank checkbox if you want to ignore blank spaces.

  8. If you want to add a Title and message for your rule, select the Input Message tab, and then type a title and input message.

  9. Select the Show input message when cell is selected checkbox to display the message when the user              selects or hovers over the selected cell(s).

  10. Select OK.

     Now, if the user tries to enter a value that is not valid, a pop-up appears with the message, "This value doesn't match the data validation restrictions for this cell."

If you're creating a sheet that requires users to enter data, you might want to restrict entry to a certain range of dates or numbers, or make sure that only positive whole numbers are entered. Excel can restrict data entry to certain cells by using data validation, prompt users to enter valid data when a cell is selected, and display an error message when a user enters invalid data.

Restrict data entry

  1. Select the cells where you want to restrict data entry.

  2. On the Data tab, click Data Validation > Data Validation.

    Note: If the validation command is unavailable, the sheet might be protected or the workbook might be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. In the Allow box, select the type of data you want to allow, and fill in the limiting criteria and values.

    Note: The boxes where you enter limiting values will be labeled based on the data and limiting criteria that you have chosen. For example, if you choose Date as your data type, you will be able to enter limiting values in minimum and maximum value boxes labeled Start Date and End Date.

Prompt users for valid entries

When users click in a cell that has data entry requirements, you can display a message that explains what data is valid.

  1. Select the cells where you want to prompt users for valid data entries.

  2. On the Data tab, click Data Validation > Data Validation.

    Note: If the validation command is unavailable, the sheet might be protected or the workbook might be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. On the Input Message tab, select the Show input message when cell is selected check box.

  4. In the Title box, type a title for your message.

  5. In the Input message box, type the message that you want to display.

Display an error message when invalid data is entered

If you have data restrictions in place and a user enters invalid data into a cell, you can display a message that explains the error.

  1. Select the cells where you want to display your error message.

  2. On the Data tab, click Data Validation > Data Validation.

    Note: If the validation command is unavailable, the sheet might be protected or the workbook might be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. On the Error Alert tab, in the Title box, type a title for your message.

  4. In the Error message box, type the message that you want to display if invalid data is entered.

  5. Do one of the following:

    To

    On the Style pop-up menu, select

    Require users to fix the error before proceeding

    Stop

    Warn users that data is invalid, and require them to select Yes or No to indicate if they want to continue

    Warning

    Warn users that data is invalid, but allow them to proceed after dismissing the warning message

    Important

Restrict data entry

  1. Select the cells where you want to restrict data entry.

  2. On the Data tab, under Tools, click Validate.

    Data tab, Tools group

    Note: If the validation command is unavailable, the sheet might be protected or the workbook may be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. On the Allow pop-up menu, select the type of data you want to allow.

  4. On the Data pop-up menu, select the type of limiting criteria that you want, and then enter limiting values.

    Note: The boxes where you enter limiting values will be labeled based on the data and limiting criteria that you have chosen. For example, if you choose Date as your data type, you will be able to enter limiting values in minimum and maximum value boxes labeled Start Date and End Date.

Prompt users for valid entries

When users click in a cell that has data entry requirements, you can display a message that explains what data is valid.

  1. Select the cells where you want to prompt users for valid data entries.

  2. On the Data tab, under Tools, click Validate.

    Data tab, Tools group

    Note: If the validation command is unavailable, the sheet might be protected or the workbook may be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. On the Input Message tab, select the Show input message when cell is selected check box.

  4. In the Title box, type a title for your message.

  5. In the Input message box, type the message that you want to display.

Display an error message when invalid data is entered

If you have data restrictions in place and a user enters invalid data into a cell, you can display a message that explains the error.

  1. Select the cells where you want to display your error message.

  2. On the Data tab, under Tools, click Validate.

    Data tab, Tools group

    Note: If the validation command is unavailable, the sheet might be protected or the workbook may be shared. You cannot change data validation settings if your workbook is shared or your sheet is protected. For more information about workbook protection, see Protect a workbook.

  3. On the Error Alert tab, in the Title box, type a title for your message.

  4. In the Error message box, type the message that you want to display if invalid data is entered.

  5. Do one of the following:

    To

    On the Style pop-up menu, select

    Require users to fix the error before proceeding

    Stop

    Warn users that data is invalid, and require them to select Yes or No to indicate if they want to continue

    Warning

    Warn users that data is invalid, but allow them to proceed after dismissing the warning message

    Important

Add data validation to a cell or a range

Note: The first two steps in this section are for adding any type of data validation. Steps 3-7 are specifically for creating a drop-down list. 

  1. Select one or more cells to validate.

  2. On the Data tab, in the Data Tools group, click Data Validation.

  3. On the Settings tab, in the Allow box, select List.

  4. In the Source box, type your list values, separated by commas. For example, type Low,Average,High.

  5. 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.

  6. To specify how you want to handle blank (null) values, select or clear the Ignore blank check box.

  7. 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.

Notes: 

  • After you create your drop-down list, make sure it works the way you want. For example, you might want to check to see if the cell is wide enough to show all your entries.

  • Remove data validation - Select the cell or cells that contain the validation you want to delete, then go to Data > Data Validation and in the data validation dialog press the Clear All button, then click OK.

The following table lists other types of data validation and shows you ways to add it to your worksheets.

To do this:

Follow these steps:

Restrict data entry to whole numbers within limits.

  1. Follow steps 1-2 above.

  2. From the Allow list, select Whole number.

  3. In the Data box, select the type of restriction that you want. For example, to set upper and lower limits, select between.

  4. Enter the minimum, maximum, or specific value to allow.

    You can also enter a formula that returns a number value.

    For example, say you're validating data in cell F1. To set a minimum limit of deductions to two times the number of children in that cell, select greater than or equal to in the Data box and enter the formula, =2*F1, in the Minimum box.

Restrict data entry to a decimal number within limits.

  1. Follow steps 1-2 above.

  2. In the Allow box, select Decimal.

  3. In the Data box, select the type of restriction that you want. For example, to set upper and lower limits, select between.

  4. Enter the minimum, maximum, or specific value to allow.

    You can also enter a formula that returns a number value. 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.

Restrict data entry to a date within range of dates.

  1. Follow steps 1-2 above.

  2. In the Allow box, select Date.

  3. In the Data box, select the type of restriction that you want. For example, to allow dates after a certain day, select greater than.

  4. Enter the start, end, or specific date to allow.

    You can also enter a formula that returns a date. 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 Start date box, and enter =TODAY()+3 in the End date box.

Restrict data entry to a time within a time frame.

  1. Follow steps 1-2 above.

  2. In the Allow box, select Time.

  3. 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.

  4. Enter the start, end, or specific time to allow. If you want to enter specific times, use the hh:mm time format.

    For example, say you have cell E2 set up with a start time (8:00 AM), and cell F2 with an end time (5:00 PM), and you want to limit meeting times between those times then select between in the Data box, enter =E2 in the Start time box, and then enter =F2 in the End time box.

Restrict data entry to text of a specified length.

  1. Follow steps 1-2 above.

  2. In the Allow box, select Text Length.

  3. 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.

  4. In this case we want to limit entry to 25 characters, so select less than or equal to in the Data box and enter 25 in the Maximum box.

Calculate what is allowed based on the content of another cell.

  1. Follow steps 1-2 above.

  2. In the Allow box, select the type of data that you want.

  3. In the Data box, select the type of restriction that you want.

  4. 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 E1, select Allow >Whole number, Data, less than or equal to, and Maximum >= =E1.

Notes: 

  • The following examples use the Custom option where you write formulas to set your conditions. You don't need to worry about whatever the Data box shows, as that's disabled with the Custom option.

  • The screen shots in this article were taken in Excel 2016; but the functionality is the same in Excel Online.

To make sure that

Enter this formula

The cell that contains a product ID (C2) always begins with the standard prefix of "ID-" and is at least 10 (greater than 9) characters long.

=AND(LEFT(C2,3)="ID-",LEN(C2)>9)

Example 6: Formulas in data validation

The cell that contains a product name (D2) only contains text.

=ISTEXT(D2)

Example 2: Formulas in data validation

The cell that contains someone's birthday (B6) has to be greater than the number of years set in cell B4.

=IF(B6<=(TODAY()-(365*B4)),TRUE,FALSE)

Data validation example to restrict an entry to a minimum age

All the data in the cell range A2:A10 contains unique values.

=COUNTIF($A$2:$A$10,A2)=1

Example 4: Formulas in data validation

Note: You must enter the data validation formula for cell A2 first, then copy A2 to A3:A10 so that the second argument to the COUNTIF will match the current cell. That is the A2)=1 portion will change to A3)=1, A4)=1 and so on.

For more information

Ensure that an e-mail address entry in cell B4 contains the @ symbol.

=ISNUMBER(FIND("@",B4))

Data validation example ensuring an e-mail address contains the @ symbol

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.

See also

More on data validation

Add or remove items from a drop-down list

Remove a drop-down list

No comments:

Post a Comment