LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Another Question about Date Formatting

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional formatting for cell date to equal today's date Sistereinstein Excel Worksheet Functions 2 September 10th 12 07:53 PM
Numeric date to text..formatting question JHB Excel Discussion (Misc queries) 2 October 4th 08 07:46 PM
Excel Conditional Formatting a Date Question Todd Excel Discussion (Misc queries) 2 April 19th 07 04:28 PM
Another Date/Cell Color/Condition Formatting Question Millerk Excel Discussion (Misc queries) 1 March 1st 06 05:20 PM
Cell / Date Formatting Question when result = -0- seve Excel Discussion (Misc queries) 3 January 17th 05 02:29 AM


All times are GMT +1. The time now is 11:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"