ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell Data Types (Date vs. Double) (https://www.excelbanter.com/excel-programming/302339-cell-data-types-date-vs-double.html)

Mike[_86_]

Cell Data Types (Date vs. Double)
 
Hello All:

I have a spreadsheet with two columns both containing serial date/time.
Column A is formatted using a valid date format and column B is formatted
using a valid time format.

If I use the following:

SourceArray = Range.Value
Assuming that Range is a selection of two columns and at least one row.

TypeName(SourceArray(1,1))
returns Date
TypeName(SourceArray(1,2))
returns Double

Does Excel not evaluate a column formatted as time to be a valid portion of
a date and therefore type the value as a Date?

Any insight would be greatly appreciated.

Mike.



BrianB

Cell Data Types (Date vs. Double)
 
Don't really know the answer, but VBA obligingly changes data types to
whatever the variable is formatted to. This can be very useful, for
example, when wanting to convert Text to numbers or vice versa.

Perhaps, in this case, it recognises your date data as such and does
its thing (because it just loves to convert dates to American mm/dd/yy
) but does not recognise Times.

"It's a feature, not a bug.":rolleyes:


---
Message posted from http://www.ExcelForum.com/


Mike[_86_]

Cell Data Types (Date vs. Double)
 
Everyone:

Brian, thank you for you response.

The following is a debug.print of the values I am working with.

Before Format: 37417.3433796296, 37417.3433796296
After Format: 10/06/2002 8:14:28 AM, 37417.3433796296

Format Strings: dd/MM/yyyy, h:mm:ss

Notice how the Col A value has been converted when a date format is applied
but the Col B value remains unchanged.

"BrianB " wrote in message
...
Don't really know the answer, but VBA obligingly changes data types to
whatever the variable is formatted to. This can be very useful, for
example, when wanting to convert Text to numbers or vice versa.

Perhaps, in this case, it recognises your date data as such and does
its thing (because it just loves to convert dates to American mm/dd/yy
) but does not recognise Times.

"It's a feature, not a bug.":rolleyes:


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 04:51 AM.

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