September 3, 2016
November 8, 2013
You're right, there should be more options for inputbox validations.
You can put the inputbox in a loop, and exit the loop only when the input is a valid date. If the user will not type a valid date, he will be running in circles until they manage to type a date 🙂
The good part using this approach is that it will accept many date strings, like January 23, 2016, or 12/12/2016. You control the output by formatting the result of the input box, no matter what date format was typed.
Dim DateInput As Variant
DateInput = InputBox("Date:", "Dates Only")
If IsDate(DateInput) Then Exit Do
If Not IsDate(DateInput) Then MsgBox "Try again, that was not a valid date", vbCritical + vbOKOnly, "Dates Only"
Sheet1.Cells(1).NumberFormat = "mm/dd/yyyy": Sheet1.Cells(1).Value = DateInput
October 5, 2010
You could use a date picker in your form so the date is always in a known format. No typing required for the user either.
June 25, 2016
Dates are pretty tough to handle given the different formats (US/UK formats) and selecting them from a list is the best as mentioned by Philip.
I normally allow users to enter the dates with some validation using a userform. Here is a simple userform to share with you that validate both dates and numbers.
September 3, 2016
Excellent, three very useful tips for handling dates thank you. I'm not sure which will suit me best right now so will give all three a try. The lack of control over the InputBox formatting is often frustrating, especially after designing a visually pleasing and bespoke user form.
Most Users Ever Online: 57
Currently Browsing this Page:
Frans Visser: 210
mey tithveasna: 71
Anders Sehlstedt: 47
Guest Posters: 1
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea
Moderators: Genevieve Tupas