View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Nate[_7_] Nate[_7_] is offline
external usenet poster
 
Posts: 9
Default Date validation with abiguous format

Thanks all!

I found that using the VBA function "dateserial" is going to work the
best. This will convert the text into an Excel date serial number and
I can use that for evaluating.

Dt = DateSerial(Left(C.Text, 4), Mid(C.Text, 5, 2), Right(C.Text, 2))

Thanks,
Nate


Bob Phillips wrote:
Dim sDate As String
sDate = 20061111
MsgBox IsDate(Left(sDate, 4) & "-" & Mid(sDate, 5, 2) & "-" & Right(sDate,
2))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
oups.com...
Hi all,

I'm working on developing a date validation where the user enters into
a cell a date in the format "yyyymmdd". The validation must happen
after the entry, so I'm not able to use a simple validation function,
or even cell formatting (due to copying/pasting into the cell). The
code has to recognize that this "number" is a valid date. So far I've
defined a variable that extracts the text of this number into a more
friendly date format and then decides if it's a valid date.

Dt = Mid(C.Text, 5, 2) & "/" & Right(C.Text, 2) & "/" & Left(C.Text, 4)
If Dt.... End If

Is there an easier way to do this? Is there a function that says - if
this number in "yyyymmdd" format is a valid date, then do this... ?

Thanks,
Nate