Limit date to a specific day in a cell
This tutorial shows how to only allow entry of dates that have a specific day using Excel or VBA
METHOD 1. Limit date to only allow entry of dates that have a specific 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 day. Note: in this example we are selecting range B2. |
2. Select the Data tab. |
3. Click on Data Validation in the Data Tools group. 4. Select Data Validation. |
5. Select the Settings tab. 6. Select Custom in the Allow input box. 7. Enter the formula =DAY(B2)=10 in the Formula input box. 8. Click OK |
METHOD 1. Limit date to a specific day in a cell
VBA
Sub Limit_date_to_day()
'declare variables
Dim ws As Worksheet
Dim Rng As Range
Dim ws As Worksheet
Dim Rng As Range
Set ws = Worksheets("Analysis")
Set Rng = ws.Range("B2")
Set Rng = ws.Range("B2")
'apply data validation
With Rng.Validation
With Rng.Validation
.Add Type:=xlValidateCustom, Formula1:="=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 day by changing the cell reference ("B2") in the VBA code.
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 day by changing the cell reference ("B2") in the VBA code.
EXPLANATION
This tutorial shows how to only allow entry of dates that have a specific 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 day. It uses a custom formula (=DAY(B2)=day) in the Data Validation dialog box and can be completed in eight steps. You can nominate any day by replacing 'day' with a day number in the formula above. In this example we have restricted to only the 10th day of a 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 day.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Limit date to a specific month in a cell | How to only allow entry of dates that have a specific month | |
Limit date to a specific year in a cell | How to only allow entry of dates that have a specific year | |
Allow date less than today in a cell | How to only allow entry of dates in a cell that are less than the current date | |
Allow date greater than today in a cell | How to only allow entry of dates in a cell that are greater than the current date | |
Limit number of characters in a cell | How to allow to only enter n number of characters in a cell |