How to Prevent Future Dates in an Excel VBA Date Picker
Question details
The user wants to restrict a VBA date picker from accepting dates later than the current day and validate the selection before assigning it to a cell or variable.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Creating a UserForm or macro that requires date input via a date picker, where future dates (like a future birth date or past event log) are invalid.
- Observed behavior
- The date picker allows future dates to be selected and assigned to the active cell or a result variable without any restriction.
Ensure you have the Developer tab enabled in your spreadsheet application and have basic familiarity with the VBA Editor (Alt + F11).
Validate the Date Before Variable Assignment
Add a simple VBA IF statement to ensure the selected date is valid and not in the future before passing it to a cell or variable.
While the date picker UI might still visually display future dates depending on its specific control properties, you can easily prevent invalid dates from being saved by intercepting the value in your VBA code.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications editor.
Find the sub-routine in your UserForm where the date picker's value is assigned to a cell (for example, where you have written 'ActiveCell = PickedDate').
Wrap your assignment code with an IF statement to check the date. Type: 'If PickedDate > 0 And PickedDate <= Date Then'.
Place your original assignment code inside the IF block, such as 'ActiveCell = PickedDate' or 'ResultDate = PickedDate'.
Add 'End If' to complete the validation. You can also add an 'Else' block with a 'MsgBox' to warn the user that they selected an invalid future date.

Create and Manage VBA UserForms with WPS Office
WPS Spreadsheets offers robust VBA support, allowing you to seamlessly create user forms, implement date pickers, and run complex macros with high compatibility.
- 1. Download and Install: Download and install WPS Office for free from the official website.
- 2. Enable Developer Tools: Open WPS Spreadsheets, navigate to the top ribbon, and click on the Developer tab.
- 3. Launch the VBA Editor: Click on 'VBA Editor' to launch the programming environment.
- 4. Implement Your Form: Insert your UserForm, add the date picker control, and paste your data validation code to ensure accurate data entry.

Frequently Asked Questions
How do I visually disable future dates on the Date Picker control itself?
If you are using the standard MSComCtl2.DTPicker control, you can set its MaxDate property to 'Date' (today) in the UserForm_Initialize event. This will gray out future dates and physically prevent the user from clicking them.
How can I alert the user when they pick an invalid future date?
You can add an 'Else' statement to the validation code block and use 'MsgBox "Please select a date on or before today.", vbExclamation' to immediately notify the user of their mistake.
Why doesn't the date picker control appear in my VBA toolbox?
The standard VBA toolbox doesn't include a date picker by default. You need to right-click the toolbox, select 'Additional Controls', and check 'Microsoft Date and Time Picker Control'. If it is missing, you may need to register the mscomct2.ocx file on your Windows system.




