General vs Date format question

B

Brad

Using 2007 (but need compatibility with 2003)

I want the "look" at what was entered - if the date contains "slashes" leave
it alone - if not, add the slashes. My main concern is to know what is the
"format" in data entered (regardless on how the cell is formatted) - I can
add the slashes as needed.
 
J

Joel

First, rember a date is a positive number. So when you do ISDARE() it is
checking for a valid number that can be any date after Jan 1, 1900 which
equals 1.

You really want to check the numberformat property like this

Set MyCell = Range("A1")
Dateformat = MyCell.NumberFormat
If InStr(Dateformat, "/") = 0 Then 'check if the number format contains a
slash
'enter your code here
End If
 
J

Joel

First, remember a date is a positive number. So when you do ISDARE() it is
checking for a valid number that can be any date after Jan 1, 1900 which
equals 1.

You really want to check the numberformat property like this

Set MyCell = Range("A1")
Dateformat = MyCell.NumberFormat
If InStr(Dateformat, "/") = 0 Then 'check if the number format contains a
slash
'enter your code here
End If
 
D

Dave Peterson

?isdate(clng(date))
False

IsDate checks to see if the expression can be converted to a date. It can be a
string or a real date.
 

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

Top