Data Validation in Excel is a feature that allows you to control input data type
Data Validation in Excel helps ensure data accuracy and consistency in spreadsheets, reducing the chance of errors in data entry. Data validation can be used to create dropdown lists, restrict data types (like numbers, dates, or text), or even validate data using custom formulas.
In this tutorial, we’ll cover everything you need to know about Data Validation in Excel, including its core functions and features, step-by-step instructions.
1. What is Data Validation in Excel?
Data Validation is a feature that restricts the type of data or the values that users can enter into a cell. You can use it to:
- Limit the type of data (e.g., only allow whole numbers, dates, or decimals).
- Create dropdown lists for easier data entry.
- Ensure data meets certain criteria using custom formulas.
This ensures data integrity and makes your spreadsheets more user-friendly, especially when others are entering data.
2. How to Access Data Validation
To use Data Validation in Excel, follow these steps:
- Select the cell or range where you want to apply data validation.
- Go to the Data tab on the Ribbon.
- Click Data Validation in the Data Tools group.
- The Data Validation dialog box will appear, where you can set the rules.
3. Types of Data Validation Rules
Excel provides several built-in validation rules, which you can choose from in the Settings tab of the Data Validation dialog box:
1. Whole Numbers
This rule restricts the input to whole numbers (no decimals). You can set conditions such as:
- Between: Only allows numbers within a specific range.
- Not Between: Excludes numbers within a range.
- Equal To, Greater Than, or Less Than: Limits values based on specific conditions.
Example: Allow numbers between 1 and 100 in a cell:
- Select the range of cells.
- In the Data Validation dialog box, set the Allow field to Whole Number and choose between 1 and 100.
2. Decimal Numbers
Allows users to enter decimal numbers, providing flexibility for ranges or values that require fractional numbers.
Example: Only allow numbers between 1.5 and 10.5:
- Set Allow to Decimal, and select between with minimum 1.5 and maximum 10.5.
3. List (Dropdown)
The List option creates a dropdown menu in the selected cell, letting users select from a predefined set of choices. This is particularly useful for standardizing entries.
Example: Create a dropdown list for selecting departments:
- Set Allow to List.
- Enter options like
Sales, HR, Marketing
into the Source field (comma-separated), or reference a range in your worksheet that contains the list.
One of the most powerful uses of Data Validation in Excel is creating dependent dropdown lists. This means the options in a dropdown list depend on the selection made in another dropdown. For example, choosing a category (like “Fruits”) in one list determines what options (like “Apple,” “Banana,” etc.) appear in the second list.
What is a Dependent Dropdown List?
A dependent dropdown list means that the items shown in a second dropdown are determined by the choice made in a first dropdown. It’s a dynamic list that changes based on the user’s previous selection.
To achieve this in Excel, the INDIRECT function is commonly used. This allows you to reference a named range dynamically, based on the value chosen in the first dropdown.
How to Create a Dependent Dropdown List Using INDIRECT
Here’s a step-by-step guide to setting up dependent dropdown lists in Excel using the INDIRECT function:
Step 1: Create Named Ranges
For dependent dropdowns to work, you need to define Named Ranges for your data.
- Create the Main Categories (e.g., Fruits, Vegetables, Beverages):
- In one column, list your main categories (e.g., Column A: “Fruits”, “Vegetables”, “Beverages”).
- Define the Options for Each Category:
- In separate columns, list the items for each category. For example:
- Column B: “Apple,” “Banana,” “Orange” (under the heading Fruits).
- Column C: “Carrot,” “Spinach,” “Potato” (under Vegetables).
- Column D: “Water,” “Juice,” “Soda” (under Beverages).
- In separate columns, list the items for each category. For example:
- Create Named Ranges for Each Category:
- Highlight the range of items under each category (e.g., select the cells for “Apple,” “Banana,” and “Orange”).
- Go to the Formulas tab and click Define Name.
- Name the range exactly the same as the category (e.g., name the range for fruits “Fruits”).
- Repeat this process for the other categories (“Vegetables,” “Beverages”).
Step 2: Create the First Dropdown List
- Select the cell where you want the first dropdown (the one with the main categories).
- Go to Data > Data Validation.
- In the Settings tab, choose List under Allow.
- In the Source field, input the range of your main categories or simply select them (e.g.,
=A1:A3
). - Click OK. Now, the first dropdown list will show “Fruits,” “Vegetables,” and “Beverages.”
Step 3: Create the Dependent Dropdown List
- Select the cell where you want the dependent dropdown.
- Go to Data > Data Validation again.
- In the Settings tab, choose List under Allow.
- In the Source field, use the INDIRECT function to refer to the first dropdown:
=INDIRECT(A8)
- Click OK. Now, the dependent dropdown will change dynamically based on the selection in the first dropdown.
In this setup:
- When “Fruits” is selected in the first dropdown, the second dropdown will display Apple, Banana, and Orange.
- If “Vegetables” is selected, the second dropdown will show Carrot, Spinach, and Potato.
Managing Named Ranges with Dynamic Lists
If your list of options grows or shrinks over time, you can use dynamic named ranges to make sure your dropdowns always show the correct options.
Creating Dynamic Named Ranges Using OFFSET
You can create dynamic ranges that adjust automatically when items are added or removed. For example:
- Go to Formulas > Define Name.
- In the Refers to box, use the OFFSET function to create a dynamic range:
=OFFSET(Sheet1!$B$1, 0, 0, COUNTA(Sheet1!$B:$B), 1)
This formula dynamically adjusts the range in Column B based on how many non-blank cells there are.
4. Date
Restrict the cell to only accept dates within a given range.
Example: Allow only dates in the current year:
- Set Allow to Date.
- Select between, and set the start date as
01/01/2024
and the end date as12/31/2024
.
5. Time
Similar to dates, you can restrict input to specific times or time ranges.
Example: Only allow times between 9 AM and 5 PM:
- Set Allow to Time.
- Select between, and set the start time as
09:00 AM
and the end time as05:00 PM
.
6. Text Length
This rule restricts the number of characters in a cell. It’s useful when you want to limit data entries, such as product codes or ID numbers.
Example: Only allow text entries that are exactly 6 characters long:
- Set Allow to Text Length and select equal to 6.
7. Custom (Formulas)
For more advanced validation, you can use custom formulas to define your criteria. The formula must return TRUE
or FALSE
. If it returns TRUE
, the input is accepted; if FALSE
, the input is rejected.
Example: Allow only values that are multiples of 5:
Set Allow to Custom and use the formula:
=MOD(A1, 5) = 0
Here, the cell will only accept numbers divisible by 5.
4. Error Alerts and Input Messages
Data Validation offers two key features to enhance user experience and guide them in entering valid data:
Input Message:
You can display a message that provides instructions on what kind of data should be entered when the user selects a cell.
- To set an Input Message:
- In the Data Validation dialog box, go to the Input Message tab.
- Enter a title and a message (e.g., “Please select a date between January and December”).
- The message will appear as a tooltip when the user selects the cell.
Error Alert:
When a user enters invalid data, Excel displays an error message. There are three types of error alerts:
- Stop: Prevents the user from entering invalid data. The most strict option.
- Warning: Allows the user to override the error by choosing “Yes” or “No” to accept the invalid entry.
- Information: Displays an informational message but lets the user proceed with the entry.
To customize the error alert:
- Go to the Error Alert tab in the Data Validation dialog box.
- Set the Style (Stop, Warning, or Information).
- Enter a title and message to explain the error.
5. Examples of Data Validation in Action
Example 1: Create a Dropdown List for Product Categories
You can use a List validation to limit data entry to specific product categories.
Steps:
- Select the cells where you want to create the dropdown.
- Set Allow to List and input your categories (e.g.,
Electronics, Furniture, Apparel
). - Users will now see a dropdown arrow in those cells and can choose only the listed categories.
Example 2: Restrict Dates to Weekdays Only
You can use a Custom formula to restrict date entries to weekdays (excluding weekends).
Steps:
Select the date range.
Set Allow to Custom and use this formula:
=WEEKDAY(A1,2) < 6
This formula ensures only weekdays (Monday to Friday) can be entered.
6. Managing and Removing Data Validation
You can manage existing Data Validation rules by:
- Selecting the cells with validation.
- Going to Data > Data Validation.
- Viewing or modifying the rule in the Settings tab.
To remove Data Validation from cells:
- Select the cells.
- Click Data Validation and choose Clear All.
7. Limitations of Data Validation
While Data Validation is a useful tool, it has some limitations:
- It cannot apply rules across multiple worksheets at once.
- It doesn’t handle very complex logical conditions well (such as conditional formatting).
- Input messages are limited to 255 characters.
- It does not prevent users from pasting invalid data into the cells.
8. Conclusion
Data Validation in Excel is an essential feature for creating error-proof and user-friendly spreadsheets. By setting up validation rules, you ensure that only appropriate data can be entered, whether you’re restricting inputs to numbers, dates, or specific options in a list. With custom formulas and validation alerts, you can provide guidance and prevent errors, helping to maintain data integrity across your workbooks.
Sources:
Microsoft’s Official Data Validation Guide: Data Validation in Excel
You may like: