View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default determining if cell is a date or number using C#

Try looking at
Selection.NumberFormat
It will return a string like "General" for numbers and something like
"mm/dd/yyyy" for dates.
--
Gary's Student


"Kurt" wrote:

How can one determine if the cell contains a number or a date using C#.
I have a column where users occassionally type the / for dates and
occassionally dont (because their ERP system accepts either format).
So the column contains a mix of values like:

9/16/05
103105

If the format is a date I want to convert from the (almost) dateserial value
otherwise I want to convert to a string and parse the month day year.
The value2 property returns double for both and I can't figure out how to
determine which format excel is using.
I tried to work around the issue using the text property to always return
the string and then I could check for the /. Unfortunatly I found that if
the column is not wide enough the text property returns #### so that wont
work either.

How do you get the current format of the cell?
Any ideas?

Thanks,