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 |
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 |
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!!! :rolleyes: 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 |
All times are GMT +1. The time now is 02:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com