PC Review


Reply
Thread Tools Rate Thread

Determine number format of excel cell

 
 
James Bond
Guest
Posts: n/a
 
      10th Oct 2006
hi,

I am writing a program to read data from excel sheet.
while reading a cell which contains a date, it returns a number.

Eg:Suppose cell A1 contains the following date : February 13, 1900
The Range object that refers the cell, returns to me 44 as value.

By googling, I found the method to convert it back to the date format.
they are : Application.WorksheetFunction.Text(value, "mm/dd/yyyy")
or DateTime.FromOADate(double d)


But my question, is there any way i can determine if the cell has DATE
type.

I can get the format of the date by using Range.NumberFormat. But I
need to first know, if the cell is DATE type for that?

Any help would be appreciated.

Thank you.

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      10th Oct 2006
Why not read the .Text property instead of the .Value property of the range.

Or
Public Function GetVarType(InputCell As Range) As Long
'Check the help for the meaning of the return values
'But a Date will return # 7
GetVarType = VarType(InputCell.Value)
End Function

NickHK

"James Bond" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi,
>
> I am writing a program to read data from excel sheet.
> while reading a cell which contains a date, it returns a number.
>
> Eg:Suppose cell A1 contains the following date : February 13, 1900
> The Range object that refers the cell, returns to me 44 as value.
>
> By googling, I found the method to convert it back to the date format.
> they are : Application.WorksheetFunction.Text(value, "mm/dd/yyyy")
> or DateTime.FromOADate(double d)
>
>
> But my question, is there any way i can determine if the cell has DATE
> type.
>
> I can get the format of the date by using Range.NumberFormat. But I
> need to first know, if the cell is DATE type for that?
>
> Any help would be appreciated.
>
> Thank you.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data exported to excel 2007 changes cell number format to 'general' ? Vilius Mockûnas Microsoft Excel Discussion 1 28th Jun 2009 06:42 AM
how to format cell in excel for 12 digit number starting with a 0 =?Utf-8?B?bG1hdHRveA==?= Microsoft Excel Misc 2 6th Sep 2007 09:14 PM
How to determine the cell contain number only? =?Utf-8?B?RXJpYw==?= Microsoft Excel Misc 1 2nd Jul 2007 09:28 AM
Have excel export cell format other than text; need time and date not number value ogibogi@gmail.com Microsoft Excel Discussion 0 4th Aug 2006 06:48 PM
I want to stop excel deciding the number format of a cell for me =?Utf-8?B?TGl0dGVyYXJ1bQ==?= Microsoft Excel Worksheet Functions 0 5th Aug 2005 01:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:55 PM.