Data Validation in Excel
Data Validation is an Excel feature that controls what users can enter into a cell. It helps prevent incorrect data entry and ensures data accuracy.
Why Use Data Validation?
| Benefit | Description |
|---|---|
| Avoid Mistakes | Prevents users from entering invalid data. |
| Improve Accuracy | Ensures data follows specific rules. |
| Create Dropdown Lists | Allows users to select values from a list. |
| Reduce Manual Errors | Limits incorrect typing. |
Location of Data Validation
Data Tab → Data Tools Group → Data Validation
Data Validation Dialog Box
When you click Data Validation, a dialog box appears with three tabs:
| Tab | Purpose |
|---|---|
| Settings | Define validation rules. |
| Input Message | Display instructions when a cell is selected. |
| Error Alert | Show an error message for invalid entries. |
Types of Data Validation
| Validation Type | Example |
|---|---|
| Whole Number | Marks between 0 and 100 |
| Decimal | Percentage between 0 and 100 |
| Date | Only dates from current year |
| Time | Office timing between 9 AM and 6 PM |
| Text Length | Mobile number with fixed digits |
| List | Dropdown for Gender, Course, City, etc. |
| Custom | Validation using formulas |
Example 1: Marks Between 0 and 100
Steps
- Select the Marks column.
- Go to Data → Data Validation.
- In Allow, select Whole Number.
- In Data, select Between.
- Minimum = 0
- Maximum = 100
- Click OK.
Now Excel allows only numbers from 0 to 100.
Example 2: Create a Dropdown List
Dropdown lists are the most commonly used Data Validation feature.
Example Course List
| Course |
|---|
| Excel |
| Python |
| Tally |
| Power BI |
Steps to Create Dropdown
- Select the target cells.
- Go to Data → Data Validation.
- Choose List in Allow.
- In Source, type:
=Excel,Python,Tally,Power BI
- Click OK.
A dropdown arrow appears in the selected cells.
Example 3: Text Length Validation
Restrict a Mobile Number to exactly 10 digits.
Steps
- Select the Mobile Number column.
- Open Data Validation.
- Select Text Length.
- Choose Equal To.
- Enter 10.
- Click OK.
Excel accepts only 10-character entries.
Input Message
An Input Message appears when the user selects a validated cell.
| Field | Example |
|---|---|
| Title | Enter Marks |
| Message | Marks must be between 0 and 100. |
Error Alert
Error Alert appears when a user enters invalid data.
| Style | Purpose |
|---|---|
| Stop | Prevents invalid entry completely. |
| Warning | Warns user but allows entry. |
| Information | Shows information message only. |
Remove Data Validation
- Select the validated cells.
- Open Data Validation.
- Click Clear All.
- Click OK.
Keyboard Shortcut
| Shortcut | Purpose |
|---|---|
| Alt + A + V + V | Open Data Validation |
Custom Formula to Restrict Duplicate Entries
Sometimes we want a value to be entered only once in a worksheet. For example:
- Student ID should not be repeated.
- Employee ID should be unique.
- Mobile Number should not be duplicated.
- Invoice Number should be entered only once.
In such cases, we can use Data Validation with a Custom Formula to prevent duplicate entries.
Example: Prevent Duplicate Student IDs
| Student ID |
|---|
| 1001 |
| 1002 |
| 1003 |
If a user tries to enter 1002 again, Excel should display an error message.
Custom Formula
Formula Breakdown
| Part | Meaning |
|---|---|
| COUNTIF() | Counts how many times a value appears. |
| $A$2:$A$100 | Range where IDs are stored. |
| A2 | Current cell value being checked. |
| =1 | Allows the value only if it appears once. |
Steps to Apply
- Select the cells (A2:A100).
- Go to Data → Data Validation.
- In Allow, select Custom.
- Enter the formula:
- Click OK.
Now duplicate entries will not be allowed.
Real World Examples
| Field | Formula Example |
|---|---|
| Student ID | =COUNTIF($A$2:$A$100,A2)=1 |
| Mobile Number | =COUNTIF($B$2:$B$100,B2)=1 |
| Invoice Number | =COUNTIF($C$2:$C$100,C2)=1 |
| Employee ID | =COUNTIF($D$2:$D$100,D2)=1 |
Error Alert Message
| Setting | Value |
|---|---|
| Style | Stop |
| Title | Duplicate Entry |
| Message | This value already exists. Please enter a unique value. |
=COUNTIF($A$2:$A$100,A2)=1
