This example explains how to use data validation to discard invalid dates.
- Highlight a range A2: A4.
- On the Advanced tab Data (data) click Data Validation (Data validation).
Out of date range
- From drop down list Allow (data type) select item Date (Date).
- From drop down list Data (Value) select item Between (Between).
- Enter the start and end date as shown in the picture below and click OK.Explanation: Dates between May 20, 2013 and today + 5 days are allowed. Dates outside this range are invalid.
- Type in cell A2 the date is May 19, 2013.
Result: Excel issues an error message.
Note: To specify an input hint or text to alert you to an error, click the tab Input Message (Message for input) or Error Alert (Error message).
Sundays and Saturdays
- From drop down list Allow (data type) select item Custom (Another).
- In the Formula (Formula) Enter the formula shown below and click OK.
=AND(WEEKDAY(A2)<>1,WEEKDAY(A2)<>7)
=И(ДЕНЬНЕД(A2)<>1;ДЕНЬНЕД(A2)<>7)
Explanation: Function WEEKDAY (WEEKDAY) returns a number between 1 (Sunday) and 7 (Saturday) representing the day of the week. If the day of the week is neither 1 (Sunday) nor 7 (Saturday), the date is allowed (<> means not equal). In other words, Mondays, Tuesdays, Wednesdays, Thursdays and Fridays are valid. Sundays and Saturdays – no. Since, before opening the data validation window, we selected the range A2: A4, Excel automatically inserted the formula into all cells in that range.
- To check this, select a cell A3 And click the Data Validation (Data validation).As you can see in the figure, this cell also contains a formula.
- Enter the date August 24, 2013 (Saturday) in the cell A2.
Result: Excel issues an error message.
Note: Click the tab Input Message (Message for input) or Error Alert (Error Message) to write an input hint or text to alert you to an error.