Date formatting problem
Hi there,
I've tried everything I can think of with this one - help!! I'm reading dates from 2 cells, storing them in variables, comparing them and then storing the resulting date in a different cell. Code currently is: If stStoredDate< stDate then stStoredDate=stDate Activecell.Offset(0,1).Value = stStoredDate End If My problem is stStoredDate = 04/09/05 (4 Sep 05 as I'm in the UK), stDate is the same, but the value in the cell is 09/04/05 (9 Apr 05). Both cells have identical formatting. If I change the formatting to 'general', stStoredDate= 38599, but the value in the cell is 38451. I've defined the dates as variants (poor quality data coming in from source, so errors appear if I define them as dates) and the original code used variants. I thought I might improve the situation by using strings, converting the incoming data by using cStr to give the variables in the above code, but even this has failed. I'm still getting what looks like a change of format, but is actually a change of number (Bizarre!) My Regional Settings show short date as dd/MM/yy; I'm not using the 1904 system; the cell formats all show American settings mm/dd/yy, so I'm using a custom setting of dd/mm/yy. This has been defined by the organisation where I work, so is being widely used. HELP!! Thanks Anne |
try <format<cell<custom and enter dd/mm/yy
"Anne CFS" wrote: Hi there, I've tried everything I can think of with this one - help!! I'm reading dates from 2 cells, storing them in variables, comparing them and then storing the resulting date in a different cell. Code currently is: If stStoredDate< stDate then stStoredDate=stDate Activecell.Offset(0,1).Value = stStoredDate End If My problem is stStoredDate = 04/09/05 (4 Sep 05 as I'm in the UK), stDate is the same, but the value in the cell is 09/04/05 (9 Apr 05). Both cells have identical formatting. If I change the formatting to 'general', stStoredDate= 38599, but the value in the cell is 38451. I've defined the dates as variants (poor quality data coming in from source, so errors appear if I define them as dates) and the original code used variants. I thought I might improve the situation by using strings, converting the incoming data by using cStr to give the variables in the above code, but even this has failed. I'm still getting what looks like a change of format, but is actually a change of number (Bizarre!) My Regional Settings show short date as dd/MM/yy; I'm not using the 1904 system; the cell formats all show American settings mm/dd/yy, so I'm using a custom setting of dd/mm/yy. This has been defined by the organisation where I work, so is being widely used. HELP!! Thanks Anne |
All times are GMT +1. The time now is 02:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com