Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Date Formats

i am having a bit of a problem with date format
manipulation. I capture a date from a text box on a form
and write it to a cell on a worksheet, in the process the
date switches from UK (dd/mm/yy) to US (mm/dd/yy) format,
despite the fact that it appears on the form in the UK
style and the cell in the worksheet has the UK date format
set. Any advice?

This is the code fragment if it is on any use:

A) tmpStr = Form1.Textbox1.text

B) Selection.Formula = tmpstr

Fragment (A) is in one procedure fragment (B) is in
another, no other manipulation takes place. I have even
tried using Format(tmpstr, "dd/mm/yy")

Murray

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Date Formats

I think xl will see you putting tmpstr in the cell and then it uses the windows
regional settings to see what order the mdy should be.

If you're settings are USA (mdy), then it'll try to make it a date using that.
Finally, it'll figure out what to show in the cell by the cell's format.

So if I plop 10/12/2003 into a cell (with my windows regional settings in mdy
order), I'll get Oct 12, 2003.

But if I do the same thing with dmy, I'll get Dec 10, 2003.

I'm not sure of a good way to force an unambiguous date using just one
textbox--maybe 3 (month, day & year???) or a calendar control???

But if you know you're expecting dd/mm/yy, maybe you could parse the string into
its pieces and then:

with no validity checks:

Option Explicit
Sub testme()

Dim TmpStr As String
Dim TmpArr As Variant

TmpStr = InputBox("dmy style")
TmpArr = Split97(TmpStr, "/")

Selection.Value = DateSerial(TmpArr(UBound(TmpArr)) + 2000, _
TmpArr(LBound(TmpArr) + 1), _
TmpArr(LBound(TmpArr)))
Selection.NumberFormat = "mmm dd, yyyy" 'just for verification
End Sub

'from Tom Ogilvy
Function Split97(sStr As Variant, sdelim As String) As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


If you're using xl2k or higher, you can replace split97 with split and delete
the function. (Split was added in xl2k.)



Murray Taylor wrote:

i am having a bit of a problem with date format
manipulation. I capture a date from a text box on a form
and write it to a cell on a worksheet, in the process the
date switches from UK (dd/mm/yy) to US (mm/dd/yy) format,
despite the fact that it appears on the form in the UK
style and the cell in the worksheet has the UK date format
set. Any advice?

This is the code fragment if it is on any use:

A) tmpStr = Form1.Textbox1.text

B) Selection.Formula = tmpstr

Fragment (A) is in one procedure fragment (B) is in
another, no other manipulation takes place. I have even
tried using Format(tmpstr, "dd/mm/yy")

Murray


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Date Formats

Dave,

Many thanks for your detailed reply. Iam using Xl2000 on XP Pro, I have
everything set to use the local UK (dd/mm/yyyy) settings and have played
about with this for ages. Working from your examples I eventually
sorted the problem by actually picking the tmpstr date from the text
box, formatting it to the US format then processing it via my code. It
now reports the date in the UK format when viewed in the sheet.

Very weird!

Murray
(remove mapson from email address)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Date Formats

Murray

You may have more success with

A) tmpStr = Form1.Textbox1.tex

B) Selection.Value = CDate(tmpstr

James.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Date Formats

Thanks for the suggestion,I'll give it a go.

Murray
(remove mapson from email address)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
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
Date Formats david d Excel Discussion (Misc queries) 2 September 14th 08 12:29 PM
Date Formats Denise Excel Discussion (Misc queries) 4 April 4th 07 08:41 PM
Date Formats Amy Excel Discussion (Misc queries) 2 January 23rd 07 05:05 AM
Date formats Craig Excel Discussion (Misc queries) 2 January 10th 07 10:30 PM
Date Formats Greenback Excel Discussion (Misc queries) 5 August 15th 06 08:32 AM


All times are GMT +1. The time now is 11:00 AM.

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

About Us

"It's about Microsoft Excel"