0% found this document useful (0 votes)
119 views

Data Validation Examples

1) The document discusses various ways to use Excel's data validation feature to reject invalid or incorrect data entries. This includes rejecting dates outside a specified range, dates that fall on weekends, values that exceed a budget limit, duplicate entries, and product codes that do not follow a specified format. 2) Dependent and dynamic drop-down lists can also be created using data validation and named ranges. Selections in one cell determine the available options in a linked cell. 3) Common data validation rules are described, such as only allowing numbers, text, or unique entries of a certain length that meet other criteria. Logical functions like AND and OR can combine multiple rules.

Uploaded by

Omprakash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

Data Validation Examples

1) The document discusses various ways to use Excel's data validation feature to reject invalid or incorrect data entries. This includes rejecting dates outside a specified range, dates that fall on weekends, values that exceed a budget limit, duplicate entries, and product codes that do not follow a specified format. 2) Dependent and dynamic drop-down lists can also be created using data validation and named ranges. Selections in one cell determine the available options in a linked cell. 3) Common data validation rules are described, such as only allowing numbers, text, or unique entries of a certain length that meet other criteria. Logical functions like AND and OR can combine multiple rules.

Uploaded by

Omprakash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

1

Reject Invalid Dates


This example teaches you how to use data validation to reject invalid dates.

1. Select the range A2:A4.

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

Outside a Date Range

3. In the Allow list, click Date.

4. In the Data list, click between.

5. Enter the Start date and End date shown below and click OK.
2

Explanation: all dates between 5/20/2016 and today's date + 5 days are allowed. All dates outside
this date range are rejected.

6. Enter the date 5/19/2016 into cell A2.

Result. Excel shows an error alert.

Note: to enter an input message and error alert message, go to the Input Message and Error Alert
tab.

Sundays and Saturdays

3. In the Allow list, click Custom.

4. In the Formula box, enter the formula shown below and click OK.

Explanation: the WEEKDAY function returns a number from 1 (Sunday) to 7 (Saturday)


representing the day of the week of a date. If a date's weekday is not equal to 1 (Sunday) AND
3

not equal to 7 (Saturday), the date is allowed (<> means not equal to). In other words, Mondays,
Tuesdays, Wednesdays, Thursdays and Fridays are allowed. Sundays and Saturdays are rejected.
Because we selected the range A2:A4 before we clicked on Data Validation, Excel automatically
copies the formula to the other cells.

5. To check this, select cell A3 and click Data Validation.

As you can see, this cell also contains the correct formula.

6. Enter the date 8/27/2016 (Saturday) into cell A2.

Result. Excel shows an error alert.

Note: to enter an input message and error alert message, go to the Input Message and Error Alert
tab.
4

Budget Limit

This example teaches you how to use data validation to prevent users from exceeding a budget
limit.

1. Select the range B2:B8.

Note: cell B10 contains a SUM function that calculates the sum of the range B2:B8.

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

3. In the Allow list, click Custom.

4. In the Formula box, enter the formula shown below and click OK.
5

Explanation: the sum of the range B2:B8 may not exceed the budget limit of $100. Therefore, we
apply data validation to the range B2:B8 (not cell B10!) because this is where the values are
entered. Because we selected the range B2:B8 before we clicked on Data Validation, Excel
automatically copies the formula to the other cells. Notice how we created an absolute reference
($B$2:$B$8) to fix this reference.

5. To check this, select cell B3 and click Data Validation.

As you can see, this cell also contains the correct formula.
6

6. Enter the value 30 into cell B7.

Result. Excel shows an error alert. You cannot exceed your budget limit of $100.

Note: to enter an error alert message, go to the Error Alert tab.

Prevent Duplicate Entries

This example teaches you how to use data validation to prevent users from entering duplicate
values.

1. Select the range A2:A20.

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

3. In the Allow list, click Custom.

4. In the Formula box, enter the formula shown below and click OK.

Explanation: The COUNTIF function takes two arguments. =COUNTIF($A$2:$A$20,A2)


counts the number of values in the range A2:A20 that are equal to the value in cell A2. This
value may only occur once (=1) since we don't want duplicate entries. Because we selected the
range A2:A20 before we clicked on Data Validation, Excel automatically copies the formula to
the other cells. Notice how we created an absolute reference ($A$2:$A$20) to fix this reference.

5. To check this, select cell A3 and click Data Validation.


8

As you can see, this function counts the number of values in the range A2:A20 that are equal to
the value in cell A3. Again, this value may only occur once (=1) since we don't want duplicate
entries.

6. Enter a duplicate invoice number.

Result. Excel shows an error alert. You've already entered that invoice number.

Note: to enter an input message and error alert message, go to the Input Message and Error Alert
tab.

Product Codes
This example teaches you how to use data validation to prevent users from entering incorrect
product codes.

1. Select the range A2:A7.

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

3. In the Allow list, click Custom.

4. In the Formula box, enter the formula shown below and click OK.

Explanation: this AND function has three arguments. LEFT(A2)="C" forces the user to start with
the letter C. LEN(A2)=4 forces the user to enter a string with a length of 4 characters.
ISNUMBER(VALUE(RIGHT(A2,3))) forces the user to end with 3 numbers. RIGHT(A2,3)
extracts the 3 rightmost characters from the text string. The VALUE function converts this text
string to a number. ISNUMBER checks whether this value is a number. The AND
Function returns TRUE if all conditions are true. Because we selected the range A2:A7 before
we clicked on Data Validation, Excel automatically copies the formula to the other cells.

5. To check this, select cell A3 and click Data Validation.


10

As you can see, this cell also contains the correct formula.

6. Enter an incorrect product code.

Result. Excel shows an error alert.

Note: to enter an input message and error alert message, go to the Input Message and Error Alert
tab.
11

Drop-down List

Drop-down lists in Excel are helpful if you want to be sure that users select an item from a list,
instead of typing their own values.

1. On the second sheet, type the items you want to appear in the drop-down list.

2. On the first sheet, select cell B1.

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

The 'Data Validation' dialog box appears.

4. In the Allow box, click List.

5. Click in the Source box and select the range A1:A3 on Sheet2.
12

6. Click OK.

Result:

Tip: If you don't want users to access the items on Sheet2, you can hide Sheet2. To achieve this,
right click on the sheet tab of Sheet2 and click on Hide.

7. You can also type the items directly into the text box, without using Sheet2. This gives the
exact same result.
13

Dependent Drop-down Lists


This example describes how to create dependent drop-down lists in Excel. Here's what we are
trying to achieve:

The user selects Pizza from a drop-down list.

As a result, a second drop-down list contains the Pizza items.

To create these dependent drop-down lists, execute the following steps.

1. On the second sheet, create the following named ranges.


14

Name Range Address


Food A1:A3
Pizza B1:B4
Pancakes C1:C2
Chinese D1:D3

2. On the first sheet, select cell B1.

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

The 'Data Validation' dialog box appears.

4. In the Allow box, click List.

5. Click in the Source box and type =Food.


15

6. Click OK.

Result:

7. Next, select cell E1.

8. In the Allow box, click List.

9. Click in the Source box and type =INDIRECT($B$1).

10. Click OK.

Result:
16

Explanation: the INDIRECT function returns the reference specified by a text string. For
example, the user selects Chinese from the first drop-down list. =INDIRECT($B$1) returns the
Chinese reference. As a result, the second drop-down lists contains the Chinese items.

Common Data Validation Rules

DATA VALIDATION RULES

1. allow numbers only- =ISNUMBER(C2) //For Salary

2. allow text only =ISTEXT(D2) // for Names

3. Allow text beginning with specific character(s) =


COUNTIF(cell,"text*") =COUNTIF(A2,"aa-*")

4. Allowing entering text of specified length

=AND(ISTEXT(I9),LEN(I9)>4,LEN(I9)<20)

5. Validation formula with the OR logic (multiple criteria)


=COUNTIF(A2,"aa-*")+COUNTIF(A2,"bb-*")

6. Case-sensitive validation formula


EXACT(LEFT(cell, number_of_chars), text)

=EXACT(LEFT(A2,3),"AA-")

7. Data validation to allow only unique entries and disallow duplicates


=COUNTIF(range, topmost_cell)<=1

=COUNTIF($A$2:$A$6, A2)<=1

8. To apply both Rule on Id field that entered Id is Number and Duplicate not allowed

=AND(ISNUMBER(A2),COUNTIF($A$2:$A$7,A2)<=1)

9. Allow dates between two dates


AND(cell>=start_date), cell<=end_date)

=AND(C2>=DATE(2017,7,1),C2<=DATE(2017,7,31))
17

10. For Email Validation


=ISNUMBER(MATCH("*@*.???",D3,0))

11. For 10 Digit Mobile Numbers

=AND(ISNUMBER(B10),LEN(B10)=10)

12. Allow weekdays or weekends only


Allow only workdays:

WEEKDAY(cell,2)<6
Allow only weekends:

WEEKDAY(cell,2)>5

Return type Numeric range Day range


1 (default) 1-7 Sunday - Saturday
2 1-7 Monday - Sunday
3 0-6 Monday - Sunday

13. Data validation allow uppercase only and text only

=AND(EXACT(C5,UPPER(C5)),ISTEXT(C5))

14. Allow only Upper Case

=AND(EXACT(C5,LOWER(C5)),ISTEXT(C5))

15. To allow whole numbers only

=L17-INT(L17)=0

You might also like