Excel Data Validation Between Dates
Excel Data Validation Between Dates. In this article, we will discuss how to implement data validation for date ranges in Excel, allowing users to select dates only within specific intervals. Having well-defined date ranges helps to effectively analyze data and reduces work overhead. Let’s look at an example to illustrate the process.
Example: Implementing Data Validation in Excel
Suppose we have a specified date interval in cells D2 and E2. D2 contains the start date (2-Oct-19), and E2 contains the end date (9-Oct-19). In cell A2, users will enter a meeting date. The criterion is to ensure that the date falls within the specified time interval.
To set up date validation in Excel, follow these steps:
- Select the cell(s) where you want to apply the validation.
- Go to Data -> Validation. Alternatively, you can use the keyboard shortcut ALT>A>V>V.
- In the “Allow” dropdown, choose “Custom.”
- In the “Formula” input box, enter the following formula: =AND(A2>=$D$2, A2<=$E$2)
- In the “Error Alert” section, provide the following message: “Enter date within the specified date interval.”
- Click “OK” to complete the process.
Now, any date entered outside the given date range (D2 to E2) will not be accepted by Excel.
To make the start date and end date fixed, you can use the following formula in the formula input box of data validation:
=AND(A2>=DATE(2019,10,2), A2<=DATE(2019,10,2))
This formula sets the date range to a specific interval. To apply this validation to other cells, you can copy A2 and use “Paste Special” for data validation only.
How it works:
The validation relies on the AND function to verify if the user-entered date meets the specified criteria.
AND(A2>=$D$2, A2<=$E$2):
- Excel first checks if the value in A2 is greater than or equal to the value in D2. If true, it returns TRUE; otherwise, it returns FALSE.
- Next, Excel checks if the value in A2 is less than or equal to the value in E2. If true, it returns TRUE; otherwise, it returns FALSE.
- If either of the criteria returns FALSE, the input is rejected.
This is how you can apply date validation in Excel. If you have any doubts or questions regarding this article or any other Excel/VBA topic, feel free to ask in the comments section below.