Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I apologize if this is redundant, but I am having a small problem. The
purpose of the following code is to allow the user to enter a date into a textbox without having to enter slashes or hyphens (040109 = 04/01/09). It works for the most part, but instead of coming out as 04/01/09, it comes out as 01/04/09. Every time it swtiches the day and month. Any suggestions as to why it might be doing this, and what I can do to fix it. Here is what I have; Private Sub txtDate_Exit(ByVal Cancel As MSForms.ReturnBoolean) Dim nDay As Long, nMonth As Long, nYear As Long Dim d As Date If IsDate(txtDate.Value) = True Then txtDate.Value = Format(txtDate.Value, "mm/dd/yy") Else: nDay = CLng(Left(txtDate.Text, 2)) nMonth = CLng(Mid(txtDate.Text, 3, 2)) nYear = CLng(Right(txtDate.Text, Len(txtDate.Text) -4 )) d = DateSerial(nYear, nMonth, nDay) txtDate.Value = d txtDate.Value = Format(txtDate.Value, "mm/dd/yy") End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
conditional formatting for cell date to equal today's date | Excel Worksheet Functions | |||
Numeric date to text..formatting question | Excel Discussion (Misc queries) | |||
Excel Conditional Formatting a Date Question | Excel Discussion (Misc queries) | |||
Another Date/Cell Color/Condition Formatting Question | Excel Discussion (Misc queries) | |||
Cell / Date Formatting Question when result = -0- | Excel Discussion (Misc queries) |