Limit date to a specific month in a cell

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


METHOD 1. Limit date to only allow entry of dates that have a specific month 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.
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 =MONTH(B2)=3 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 in a cell

VBA

Sub Limit_date_to_month()
'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:="=MONTH(B2)=3"

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 by changing the cell reference ("B2") in the VBA code.

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

EXPLANATION

EXPLANATION

This tutorial shows how to only allow entry of dates that have a specific month 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. It uses a custom formula (=MONTH(B2)=month) in the Data Validation dialog box and can be completed in eight steps. You can nominate any month by replacing 'month' with a month number in the formula above. In this example we have restricted to only the third month of a year, which is March.
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.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to only allow entry of dates that have a specific day
How to only allow entry of dates that have a specific year
How to only allow entry of dates in a cell that are less than the current date
How to only allow entry of dates in a cell that are greater than the current date
How to allow to only enter n number of characters in a cell