ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User Forms data entry - MM/DD/YYYY (https://www.excelbanter.com/excel-programming/316033-user-forms-data-entry-mm-dd-yyyy.html)

UmpaL00mpa

User Forms data entry - MM/DD/YYYY
 
I have a custom user form that pops up during one of the macros I run. In one
text box the user has to enter a date. I would like to write some code so that
the user can only enter the date in the MM/DD/YYYY format - eg. 11/07/2004.
What is the VBA code for this? Any help would by appreciated. Thank you.



Bob Phillips[_6_]

User Forms data entry - MM/DD/YYYY
 
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim cDelim As Long
cDelim = Len(TextBox1.Text) - Len(Replace(TextBox1.Text, "/", ""))
Select Case KeyAscii
Case Asc("0") To Asc("9"): 'OK
Case Asc("/"):
If cDelim = 2 Then
KeyAscii = 0
Else
cDelim = cDelim + 1
End If
Case Else: KeyAscii = 0
End Select

End Sub

This can be amended to be more specific

--

HTH

RP
(remove nothere from the email address if mailing direct)


"UmpaL00mpa" wrote in message
...
I have a custom user form that pops up during one of the macros I run. In

one
text box the user has to enter a date. I would like to write some code so

that
the user can only enter the date in the MM/DD/YYYY format - eg.

11/07/2004.
What is the VBA code for this? Any help would by appreciated. Thank you.






All times are GMT +1. The time now is 05:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com