The Data Validation feature allows rules which ensure that specific cells in a worksheet meet specified criteria or accept certain types of data, such as dates or whole numbers. We can also force users to select valid data from a list in a drop-down box. Excel can display a message that prompts users for correct entries and can even display an error alert when a user enters data incorrectly.
Some important issues concerning data validation are:
- Data validation rules work best when users type data directly into cells.
- Data validation rules do not affect pre-existing data, but can be used to visually flag existing data which does not comply with those rules.
- If existing data is deleted, then the data validation rules will apply to those cells when the user enters new data, if the cells still have had the validation rules applied.
- It is too easy to overwrite a target cell's validation rule by copying and pasting data or using the drag fill handle to enter data.
Now we will open an existing workbook and create some validation rules to show how to minimize data entry errors.
Opening an Existing Workbook
To explore some more of Excel's data entry-related features, we will open a workbook called ManagingMyData.xlsx.
Step1. To begin to open a workbook, press:
Control key+o, Click Browse
Step2. To open the desired workbook,
Double-Click ManagingMyData.xlsx
Step1. To switch to the Validation worksheet, if necessary,
Click the Validation worksheet tab
NOTE: If a cell contains a value or formula that Excel thinks may be an error, a triangle will appear in the top left corner of the cell; for example, Excel may assume that numbers should not be stored as text. To disable Error Checking, you can go to The Backstage, then open the Excel Options dialog box, Click Formulas in the left panel, and under the Error Checking category, disable the "Enable background error checking" checkbox. At any time, the background error checking tool can be enabled to locate cells that might contain errors.
NOTE for MacOS Users: To disable Error Checking, on the Menu bar, Click Excel, Click Preferences..., then Click Error Checking, and uncheck the "Turn on background error checking" checkbox in the Error Checking dialog box.
Specifying Data Validation Criteria
Validation rules can be mandatory or optional. If the rules are mandatory, Excel will refuse to accept an entry that does not meet the required standards. We can also set up advisory prompts in which the user will be prompted, but not forced, to enter particular kinds of data.
We will first select the range of cells where we want the criteria to apply, and leave some room for new hires to occur. Then we will set up a validation rule to limit the Employee ID to four characters.
Step1. To select the criteria range for the Employee ID,
Press & Drag cells A4 through A24
Step2. To view the Data tools, on the Ribbon,
Click the Data command tab
Step3. To access the Data Validation dialog box, in the Data Tools group,
Click
NOTE: Depending on the display settings of your machine, you may see a larger button.
Option | Description |
---|---|
Any Value | This option removes any existing data validation. |
Whole Number | User specifies a valid range of whole numbers (for example, greater than or equal to 100). |
Decimal | User enters a number by specifying a valid range (for example, greater than or equal to 0). Decimals are allowed. |
List | User chooses from a list of entries that are provided. |
Date | User specifies a valid date range. |
Time | User specifies a valid time range. |
Text Length | User limits the length of the data. |
Custom | User can enter a formula to determine the validity of the entry, or user can specify a cell reference that contains a formula. |
Specifying Text Length
When specifying text length, the field can be any data type. Text Length only creates a length requirement, not a requirement for the text itself.
We will make the text length four characters for the Employee ID column.
Step1. To select the Text length option, in the Allow drop-down box,
Click, Click Text length
Step2. To select a Data option, in the Data drop-down box,
Click, Click equal to, press: Tab key
Step3. To set the length to four characters, in the Length field, type:
4
Step4. To view the input message options,
Click the Input Message tab
Step5. To specify a title for the input message,
Click in the Title field, type: Employee ID Tab key
Step6. To specify the input message, in the Input message field, type:
Employee ID must be 4 digits long.
Step7. To specify an error alert,
Click the Error Alert tab
Style | Purpose |
---|---|
Stop | Prevents an invalid entry and forces the user to retry or cancel. |
Warning | Informs the user that the entry is invalid; user can still leave the entry in the cell or make another attempt. |
Information | User is told about the error but will not be given a retry option. |
Step8. Verify that the Style setting is set to Stop.
Step9. To create a title for the message,
Click in the Title field, type: Employee ID Tab key
Step10. To create the message, in the Error message field, type:
Employee ID must be 4 digits.
Step11. To close the dialog box,
Click
Specifying Date Criteria
The Date option allows us to specify a date range. We want to specify that hihre date entries must be on or before today's date.
To do this, let's first select the range of cells where we want the date criteria to apply. Then we will set up a validation rule to warn the user to enter a date on or before today's date.
Step1. To select the criteria range for the Hire Date,
Press & Drag cells D4 through D24
Step2. To open the dialog box, on the Ribbon,
Click
Step3. To activate the Settings tab,
Click the Settings tab
Step4. To select the Date option, in the Allow drop-down box,
Click, Click Date
Step5. To select the operator, in the Data drop-down box,
Click, Click less than or equal to, press: Tab key
Step6. To set up the validation criteria, in the End date field, type:
=today()
Step7. To specify an error alert,
Click the Error Alert tab
Step8. To change the Style to Warning, in the Style drop-down box,
Click, Click Warning
Step9. To create a title for the message,
Click in the Title field, type: Hire Date Tab key
Step10. To create the message, in the Error message field, type:
Hire date should be on or before today's date.
Step11. To accept these changes and close the dialog box,
Click
Creating a Drop-Down List
A common use of data validation is to create a drop-down list of items. The items may be entered directly into the Source control in the Settings tab of the Data Validation dialog box separated by commas, or for longer lists, a range for a list of items can be created on the worksheet and then entered in the dialog box.
Until now, we have applied validation rules directly to a range of cells. It is also possible to copy and paste validation rules. To show how this is done, we will set up a validation rule for a drop-down list for the Region field in one cell, and then copy this validation criteria to a range of cells.
Step1. To select the first cell under Region,
Click cell F4
Step2. To open the Data Validation dialog box, on the Ribbon,
Click
Step3. To activate the Settings tab,
Click the Settings tab
Step4. To select the List option, in the Allow drop-down field,
Click, Click List, press: Tab key
Step5. To specify the list items, in the Source field, type:
East, West, North, South
NOTE: Each item must be separated by a comma, but spaces are not required. A data range or a named range may also be specified here, using the appropriate reference syntax.
Step6. To specify an error alert,
Click the Error Alert tab
Step7. Verify that the Style setting is set to Stop.
NOTE: To allow users to type items that are not in the list, change the Error Alert to Warning or Information.
Step8. To create a title for the message,
Click in the Title field, type: Region Tab key
Step9. To create the message, in the Error message field, type:
As of 2000, region must be East, West, North, or South
Step10. To set the validation,
Click
Important Notes on Creating Drop-Down Lists
There are a few things to keep in mind when specifying data validation for a list in the Source box:
- Named ranges must be preceded by an equal (=) sign.
- Ranges specified as validation lists are not case sensitive.
- When providing a cell range in the Source box, the drop-down list will automatically be updated if any item in the list is modified.
- If the list is deleted from a specified range, then the items in the drop-down list for the validation range will not appear.
Copying and Pasting Validation Criteria
When performing a copy and paste, we may not always want to copy everything from the source range to the destination range. For example, we may not want to overwrite existing data or formulas with new data, but we may want to copy validation rules. The Paste Special dialog box gives us other options and allows more flexibility in controlling what is copied from the source range to the destination range.
Once validation criteria have been created, we can apply the same criteria to other cells without copying the data from the cells themselves. Let's see how to copy validation criteria to a new range for the Region field so that the same data validation rules for the drop-down list apply.
Step1. To select the validation criteria for Region, if necessary,
Click cell F4
Step2. To copy the cell, on the keyboard, press:
Control key+c
Step3. To select the cells to which we want to copy the validation criteria,
Press & Drag cells F5 through F24
Step4. Switch to the Home tab.
Step5. To open the Paste Special dialog box,
Click, Click Paste Special...
NOTE: The keyboard shortcut to open the Paste Special dialog box is Control key+Alt key+v.
NOTE for MacOS Users: The keyboard shortcut to open the Paste Special dialog box is Command key+Control key+v.
Paste Option | Pastes This From Copied Source Range |
---|---|
All | Contents, formats, and data validation from the Clipboard. |
Formulas | Formulas in the source range. |
Values | Results of copied formulas. |
Formats | Only the copied formatting. |
Comments | Only the copied cell comments. |
Validation | The validation criteria so the same data validation will apply. |
All using Source theme | All cell contents but keeps the theme from the original location. |
All except borders | Everything copied except any borders that appear in the source range. |
Column widths | Column width information from one column to another. |
Formulas and number formats | All formulas and numeric formats, but no values. |
Values and number formats | All current values and numeric formats, but not the formulas themselves. |
Step6. To select the validation option,
Click the Validation radio button
Step7. To close the Paste Special dialog box,
Click
NOTE: A Ctrl Options button will appear at the end of the selection, which will display additional paste options.
Step8. To discontinue the selection marquee, on the keyboard, press:
Esc key
Locating Cells with Existing Data Validation
Step1. To select all cells on a worksheet that are set up for data validation, on the Home tab, in the Editing group,
Click, Click Data Validation
NOTE for MacOS Users: To find all cells with data validation, on the Menu bar, Click Edit, Point Find, Click Go To..., Click Special..., Click Data Validation, and then Click All, Click OK.
Step2. To deselect the range,
Click any cell in the worksheet
Testing Existing Data
Excel's validation feature does not automatically test existing data. But we can request that such a test be performed using a tool in the Data Validation drop-down list.
Step1. Switch to the Data command tab.
Step2. To test the validity of the existing data in this sheet,
Click, Click Circle Invalid Data
Step3. To change the Region in cell F4,
Click cell F4, Click, Click South
Step4. To clear the circle from cell A4,
Click, Click Clear Validation Circles
Testing New Data
Now that we have specified our validation data criteria, we will enter a new record to test those validation rules.
Step1. To activate cell A11,
Click cell A11
Step2. To enter an Employee ID, in cell A11, type:
184 Tab key
Step3. To retry entering the correct data,
Click
Step4. To enter the correct Employee ID, type:
1848 Tab key
Step5. To enter the Last Name, type:
Gul Tab key
Step6. To enter the First Name, type:
Doug Tab key
Step7. To enter the Hire Date, type:
tomorrow's dateTab key
Step8. To cancel the error message,
Click
NOTE for MacOS Users:To cancel the error message, Click No.
Step9. In the Hire Date field, type:
today's date as MM/DD/YYYYTab key
NOTE: If you do not use the slashes in the date, Excel may use a default date format of dd-mmm.
Step10. In the Pay Rate field, type:
10.00 Tab key
Step11. In the Region field, in the drop-down box,
Click, Click North Tab key
NOTE: Be sure to separate the state from the zip code with a comma.
Step12. To enter the address, in the Address field, type:
535 W. Michigan St., Indianapolis, IN, 46202 Enter
NOTE: When entering data horizontally, if you use the Tab key key rather than the Right Arrow key, you can press Enter at the end of the row to return the cursor to the beginning of the next row where you may begin entering the new row of data. However, this will not work correctly if you make an error in a previous cell and have to go back to fix the error.
Step13. Save the file.