Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Visual Basic Getting confused with Dates
Hi, I have a problem in visual basic when using it in Excel. I am using U dates, so 1/2/2004 is 1st Feb 2004. But If in error someone puts in date such as 01/13/2004 (since there is not 13th month) visual basi assumes they have incorrectly put in the 13/01/2004. How do I stop it from doing this? I want it to return an error rathe than guessing what the person meant to put in. Thanks Darlajan -- Darlajan ----------------------------------------------------------------------- Darlajane's Profile: http://www.excelforum.com/member.php...fo&userid=1532 View this thread: http://www.excelforum.com/showthread.php?threadid=26951 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Visual Basic Getting confused with Dates
Here is one way:
Sub test() Dim dtm As Date, str As String str = "01/13/2004" Select Case Split(str, "/")(1) Case 1 To 12 Case Else: MsgBox "Error" End Select End Sub -- Rob van Gelder - http://www.vangelder.co.nz/excel "Darlajane" wrote in message ... Hi, I have a problem in visual basic when using it in Excel. I am using UK dates, so 1/2/2004 is 1st Feb 2004. But If in error someone puts in a date such as 01/13/2004 (since there is not 13th month) visual basic assumes they have incorrectly put in the 13/01/2004. How do I stop it from doing this? I want it to return an error rather than guessing what the person meant to put in. Thanks Darlajane -- Darlajane ------------------------------------------------------------------------ Darlajane's Profile: http://www.excelforum.com/member.php...o&userid=15326 View this thread: http://www.excelforum.com/showthread...hreadid=269512 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Visual Basic Getting confused with Dates
Hi What a pain! I had the same problem and a guru (bob phillips i think?) explained VBA only knows U.S. language. Format everything to use long date format so month is march not /3/ I have even used a workaround by saving data to a cell (as dateserial then refer to that cell rather than the textbox!!! good luck!!! Kenn -- N E Bod ----------------------------------------------------------------------- N E Body's Profile: http://www.excelforum.com/member.php...fo&userid=1126 View this thread: http://www.excelforum.com/showthread.php?threadid=26951 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Is Visual Basic the same as Visual Studio 2008? | Excel Worksheet Functions | |||
Visual Basic | Excel Discussion (Misc queries) | |||
changing the visual basic in office 2003 to visual studio net | Excel Discussion (Misc queries) | |||
Visual Basic | Excel Programming | |||
Visual Basic HELP | Excel Programming |