Data Validation is a feature in Microsoft Excel which restricts the values or type of data that users enter into a cell. It automatically checks whether the value entered is allowed based on the specified criteria. This step by step tutorial will assist all levels of Excel users in allowing only dates in the next 30 days.
Figure 1. Final result: Data validation date in next 30 days
Working formula: =AND(C3>TODAY(),C3<=(TODAY()+30))
Syntax of AND Function
AND function evaluates all logical tests and returns TRUE if all arguments are TRUE; FALSE if one or more arguments is FALSE
=AND(logical1, [logical2], ...)
- logical1– the first condition that we want to test
- only logical1 is required; succeeding logical conditions are optional
Syntax of TODAY Function
TODAY function returns the current date
=TODAY()
- TODAY function does not have any arguments
- It can be used in combination with other functions and mathematical operations to obtain the desired results
Setting up Our Data
Our table consists of two columns: Order No. (column B) and Delivery Date (column C). We want to restrict the delivery dates entered in column C and allow only dates falling in the next 30 days. We can do this by applying Data Validation.
Figure 2. Sample data: Data validation date in next 30 days
Supposing the date today is January 29, 2019, then the date 30 days from today would be February 28, 2019. Hence, we want to allow only the dates in between January 29, 2019 and February 28, 2019.
Allow only dates in next 30 days
We want to restrict the dates that we input in column C to dates falling in the next 30 days using Data Validation. We can do this by creating a validation rule using the AND and TODAY functions. Let us follow these steps:
Step 1. Select the cells whose values we want to restrict. In this case, select cells C3:C7
Step 2. Click the Data tab, then the Data Validation menu and select Data Validation
Figure 3. Selecting Data Validation
The Data Validation dialog box will pop up.
Figure 4. Data Validation preview
Step 3. Click the Allow: drop-down button and select Custom as Validation criteria
Step 4. Enter the following in the Formula bar: =AND(C3>TODAY(),C3<=(TODAY()+30))
Figure 5. Creating a data validation rule
Our AND formula contains two criteria. First, it evaluates if the date in C3 is greater than the date today. Next, it evaluates if the date in C3 is less than or equal to the date 30 days from today, as given by the formula TODAY()+30.
Excel stores dates as serial numbers, making it possible to perform calculations involving dates. In this example, we refer to the date today as January 29, 2019, while the date 30 days from now would be February 28, 2019.
For every date entered in column C that falls in between January 29, 2019 and February 28, 2019, the validation criteria returns TRUE, Data Validation passes and the value is allowed. Otherwise, Data Validation fails and the value is restricted.
Step 5. Click OK
We have now restricted the values in C3:C7 to allow only the dates falling in the next 30 days from today. Let us try and enter “2/21/2019” into cell C3.
Figure 6. Date falling in the next 30 days allowed by Data Validation
The date “2/21/2019” is allowed because it is only 23 days from the date today, satisfying the Data Validation rule.
Now let’s input “12/25/2018” into cell C4.
Figure 7. Past date in year 2018 restricted by Data Validation
The date “12/25/2018” is a past date, hence Data Validation has restricted the input of “12/25/2018” into cell C4. For restricted values, Excel shows a default warning message that says:
“The value you entered is not valid. A user has restricted values that can be entered into this cell.”
We are then presented with three options: Retry, Cancel or seek Help.
Let’s use another example and enter the date “6/30/2019” into cell C4.
Figure 8. Date beyond 30 days from today restricted by Data Validation
Once again, data validation fails because the date “6/30/2019” does not fall in the next 30 days from today.
Data Validation is very accurate in allowing only the values as specified in the formula or validation criteria. See below table that is filled up with dates in column C falling within the next 30 days from today, and allowed by Data Validation.
Figure 9. Output: Data Validation date in next 30 days
Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.
Leave a Comment