Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA Setting .Value to a date does not respect local system setting
I have found that using a macro to set a cell value to a date does not
generate the expected result. Consider ... Sub mcrSetDate() ActiveCell.Value = "1/2/2003" ActiveCell.NumberFormat = "dd mmm yyyy" End Sub This results in "02 Jan 2003". However if I enter "1/2/2003" into a cell directly and format it I get "01 Feb 2003". Clearly VBA is not observing the system date/time format which is set to Australian. (ie. dd/mm/yy) but it is clearly parsing the .Value to a date serial. Changing the statement to the following corrects the problem... ActiveCell.Value = DateValue("1/2/2003") However this means because my macro is dealing with data of unknown type (from a text file) I have to inspect every value to decide if it is a date so I can cast it before assigning it to the .Value. Does anyone know of a cleaner way to get around this problem. The sheet involved is always new and has never had any formatting aplied by the time the data is being placed on it. Cheers, Frank. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
setting default filter setting | Charts and Charting in Excel | |||
Setting default pivot table field setting to "sum" | Excel Discussion (Misc queries) | |||
Sending email via macro- setting the importance setting. | Excel Programming | |||
Help with setting up an Ordering system, please | Excel Programming | |||
Setting the system clock with excel | Excel Programming |