Limit date to a specific year in a cell

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


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

VBA

Sub Limit_date_to_year()
'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:="=YEAR(B2)=2018"

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

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

EXPLANATION

EXPLANATION

This tutorial shows how to only allow entry of dates that have a specific year using Excel or VBA.
This tutorial provides one Excel method that can be applied to only allow entry of dates that have a specific year. It uses a custom formula (=YEAR(B2)=year) in the Data Validation dialog box and can be completed in eight steps. You can nominate any year by replacing 'year' in the formula above. In this example we have restricted to only 2018 year.
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 year.

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 month
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