Visual Basic Getting confused with Dates

  • Thread starter Thread starter Darlajane
  • Start date Start date
D

Darlajane

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top