Hi All
This I believe has been brought up time and time again, and its one of the things I hate most about excel.
Basically, I'm in NZ, and we use DD/MM/YY format, I have this raw report from a computer system, that spits out the following:
[TABLE="width: 520"]
[tr]
[TD="class: xl65, width: 104"]02/07/14 11:10[/TD]
[TD="class: xl65, width: 104"]03/07/14 01:19[/TD]
[TD="class: xl65, width: 104"]03/07/14 06:35[/TD]
[TD="class: xl65, width: 104"]03/07/14 14:08[/TD]
[TD="class: xl65, width: 104"]04/07/14 13:58[/TD]
[/tr]
[/TABLE]
These at the raw state are text or at least not "recognized" as dates by excel.
On this I run something like this:
'#### Trims & converts all date cells ####
If .Range("T" & HeadRow) = "Received at Origin (Local)" Then
If .Range("X" & HeadRow) = "Proof Of Delivery (Local)" Then
.Range("T:X").NumberFormat = "dd/mm/yy h:mm"
For Each Cell In .Range("T:X")
Cell.Value = Trim(Cell.Value)
Next Cell
Else
'Error
End If
Else
'Error
End If
Display More
This basically checks a few header conditions, then tries to convert all the dates in the range to "dd/mm/yy h:mm" and trims the cells (cause the raw report is dirty as and every cell even blank ones have a single space in it).
This results in the following (if run on the data posted above):
[TABLE="width: 520"]
[tr]
[TD="class: xl66, width: 104, align: right"]07/02/14 11:10[/TD]
[TD="class: xl66, width: 104, align: right"]07/03/14
1:19[/TD]
[TD="class: xl66, width: 104, align: right"]07/03/14
6:35[/TD]
[TD="class: xl66, width: 104, align: right"]07/03/14 14:08[/TD]
[TD="class: xl66, width: 104, align: right"]04/07/14 13:58[/TD]
[/tr]
[/TABLE]
As you can see Excel has royally messed up the data, the first date has gone from the 2nd of July, to the 7th of February, as have the next three dates, but randomly enough the last date is correct as the 4th of July in both unworked and worked data.
So how would you guru's handle this? What commands in VBA etc can I run to ensure the data is the correct data after running? The original text string data is correct, I just need it to be recognizes as Date/Time so I can run some checks between them (measuring time elapsed between points etc).
And before you ask, my computers date setting is also the local dd/mm/yy format.
Thanks in advance.