Limit date to a specific month and day in a cell

This tutorial shows how to only allow entry of dates that have a specific month and day using Excel or VBA


METHOD 1. Limit date to only allow entry of dates that have a specific month and day in a cell using a formula

EXCEL

Select a cell > Data tab > Data Tools group > Click on Data Validation > Data Validation > Select Settings tab > Select Custom > Enter formula > Click OK

1. Select a cell in which you want to limit to only allow entry of dates that have a specific month and day.
Note: in this example we are selecting range B2.
Select a cell

2. Select the Data tab. Select the Data tab

3. Click on Data Validation in the Data Tools group.
4. Select Data Validation.
Click on Data Validation and select Data Validation

5. Select the Settings tab.
6. Select Custom in the Allow input box.
7. Enter the formula =AND(MONTH(B2)=3,DAY(B2)=10) in the Formula input box.
8. Click OK
Select Settings tab, select Custom, enter formula and click OK

METHOD 1. Limit date to a specific month and day in a cell

VBA

Sub Limit_date_to_month_day()
'declare variables
Dim ws As Worksheet
Dim Rng As Range
Set ws = Worksheets("Analysis")
Set Rng = ws.Range("B2")
'apply data validation
With Rng.Validation

.Add Type:=xlValidateCustom, Formula1:="=AND(MONTH(B2)=3,DAY(B2)=10)"

End With

End Sub

ADJUSTABLE PARAMETERS
Worksheet Selection: Select the worksheet in which you want to apply a restriction to a cell by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.
Cell: Select the cell in which you want to only allow entry of dates that have a specific month and day by changing the cell reference ("B2") in the VBA code.

Explanation about how to limit date to a specific month and day in a cell

EXPLANATION

EXPLANATION

This tutorial shows how to only allow entry of dates that have a specific month and day using Excel or VBA.
This tutorial provides one Excel method that can be applied to only allow entry of dates that have a specific month and day. It uses a custom formula (=AND(MONTH(B2)=month,DAY(B2)=day)) in the Data Validation dialog box and can be completed in eight steps. You can nominate any month in a year by replacing 'month' and any day in a month by replacing 'day' in the formula above. In this example we have restricted to only the third month in a year and the 10th day of the month.
The VBA code in this tutorial uses a Validation function with the xlValidateCustom validation type to only allow entry of dates that have a specific month and day.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to only allow entry of dates that have a specific year and month
How to only allow entry of dates that have a specific day
How to only allow entry of dates that have a specific month
How to only allow entry of dates that have a specific year