Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Is this cell formatted as a date?

  Asked By: Arland    Date: Feb 10    Category: MS Office    Views: 754
  

Excell 2003
Win XP

In VBA, how can I ask: Is this cell formatted as a date?

This seems so simple but I can't figure it out.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Eshe Chalthoum     Answered On: Feb 10

You question is so deceptively simple... yet confusing.

Who are you asking?
Are you wanting to prompt the user, or are you trying to determine
if a specific cell  is formatted  as a date?

If you're asking the user, then use something like:
Result = msgbox ("Is this cell formatted as a date?", vbyesno)
if (result = vbyes) then...

If you're trying to check the formatting of the cell,
are you concerned about the actual cell format (regardless of content)
or are you really trying to determine if the contents of the cell
is a valid date?

if you're checking the actuall format of the cell:
Try recording a macro that changes the formatting of a cell to several
valid date  formats.
you can then modify the macro to test any cell to determine if the
formatting matches one of the date formats
if selection.numberformat = "yyyy-mm-dd;@" _
or selection.numberformat = "dd/mm/yy;@" then
end if

if you're wanting to test the cell contents, try using:
if (isdate(selection.value)) then///

 
Answer #2    Answered By: Waggoner Fischer     Answered On: Feb 10

I guess my question should have been:
How can I programmatically determine whether a cell  contains a valid
date?

Your third response hit the nail on the head.

This brings up a question however: isn't a date  just any number that
has the date formatting applied to it? What would constitute a non-
valid date?

 
Didn't find what you were looking for? Find more on Is this cell formatted as a date? Or get search suggestion and latest updates.




Tagged: