In this article, we will talk about how to accept valid dates only from users in Excel VBA by using the formula and user-defined function in VBA. Let’s see them below!! Get an official version of ** MS Excel** from the following link: https://www.microsoft.com/en-in/microsoft-365/excel
Example
- Firstly, in the Excel Worksheet, you have to go to the Developer Tab.
- Then, you need to ** ** select the Visual Basic option under the Code section.

- Now, you have to copy and paste the code given below.
Sub check_date()
Dim dob As Date
On Error GoTo Errorhandler
dob = Application.InputBox("Enter Your Date of Birth")
On Error GoTo 0
Debug.Print dob
Exit Sub
Errorhandler:
MsgBox "Please enter a valid date."
End Sub
- After that, you need to save the code by selecting it and then close the window.

- Again, you have to go to the Excel Spreadsheet , and click on the Developer Tab.
- You need to choose the Macros option in the Code section.

- Then, you have to make sure that your macro name is selected and click the *Run * button.

- Now, you will receive an input ** dialog box, and then you need to **type date in the text box.

- After that, if you enter a valid date , it will accept as dates from users.
- Finally, if you don’t enter any date , then you will receive display dialog box as given below.

Wrap-Up
Here, we have explained the step-by-step procedure to accept valid dates only from users in Excel VBA. Make use of this. Please share your worthwhile feedback in the below comment section. To learn more, check out our website Geek Excel!!
Keep Reading:
- Excel Formulas to Show Checkmark for Valid Inputs ~ Simple Tutorial!!
- How to Set Data Validation To Accept Only IP Addresses in Excel?
- How to Modify and Manage Multiple Cell Comments in Excel Office 365?
- How to Remove/Add Author Name in Comments in Excel 365?
- Excel Formulas to Create Date Range From Two Dates ~ Quick Tricks!!
Top comments (0)