Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
Is Visual Basic the same as Visual Studio 2008? Mike Stewart Excel Worksheet Functions 5 January 11th 09 04:58 PM
Visual Basic osaka78 Excel Discussion (Misc queries) 5 September 17th 07 01:21 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic [email protected] Excel Programming 2 April 21st 04 10:32 PM
Visual Basic HELP Tony Excel Programming 2 January 2nd 04 11:23 PM


All times are GMT +1. The time now is 03:58 PM.

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"