ouestque
asked on
Excel: only allow user to enter a date
What VBA would I need so that a user can only enter a date in my textbox in my Excel spreadsheet. (i.e. if the user enters "Hello", the textbox won't allow it, maybe it will delete "Hello" and display a messagebox saying: "Dates only please" etc.)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome answers thanks!
do you mean a textbox or a cell? A date is a number, so data validation code for a cell only needs to check if the number is greater than 0, like the code below. If you want to limit data entry of future dates, then the previous code will work, if you add a closing parens in the NOW() parameter.
You can also specify that the maximum date is, for example 30 days from today. For this, use
Formula2:="=NOW()+30"
If you want to validate a textbox, the code will need to be completely different. Please clarify.
cheers, teylyn
Open in new window