Data Validation Examples
Data Validation Examples
2. On the Data tab, in the Data Tools group, click Data Validation.
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.
Note: to enter an input message and error alert message, go to the Input Message and Error Alert
tab.
4. In the Formula box, enter the formula shown below and click OK.
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.
As you can see, this cell also contains the correct formula.
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.
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.
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.
As you can see, this cell also contains the correct formula.
6
Result. Excel shows an error alert. You cannot exceed your budget limit of $100.
This example teaches you how to use data validation to prevent users from entering duplicate
values.
2. On the Data tab, in the Data Tools group, click Data Validation.
7
4. In the Formula box, enter the formula shown below and click OK.
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.
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.
2. On the Data tab, in the Data Tools group, click Data Validation.
9
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.
As you can see, this cell also contains the correct formula.
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.
3. On the Data tab, in the Data Tools group, click Data Validation.
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
3. On the Data tab, in the Data Tools group, click Data Validation.
6. Click OK.
Result:
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.
=AND(ISTEXT(I9),LEN(I9)>4,LEN(I9)<20)
=EXACT(LEFT(A2,3),"AA-")
=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)
=AND(C2>=DATE(2017,7,1),C2<=DATE(2017,7,31))
17
=AND(ISNUMBER(B10),LEN(B10)=10)
WEEKDAY(cell,2)<6
Allow only weekends:
WEEKDAY(cell,2)>5
=AND(EXACT(C5,UPPER(C5)),ISTEXT(C5))
=AND(EXACT(C5,LOWER(C5)),ISTEXT(C5))
=L17-INT(L17)=0