ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   General vs Date format question (https://www.excelbanter.com/excel-programming/425765-general-vs-date-format-question.html)

Brad

General vs Date format question
 
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.


joel

General vs Date format question
 
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


"Brad" wrote:

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.


joel

General vs Date format question
 
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

"Brad" wrote:

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.


Dave Peterson

General vs Date format question
 
?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.



Joel wrote:

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

"Brad" wrote:

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.


--

Dave Peterson

Dave Peterson

General vs Date format question
 
I'd start at Chip Pearson's site:
http://cpearson.com/excel/DateTimeEntry.htm



Brad wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com