Thursday, 8 August 2013

Specify date format of a large amount of input data

Specify date format of a large amount of input data

I have an input spreadsheet that needs to get sorted by date. The current
format of the date is in the UK format (dd/mm/yyyy) but I need it in
yyyy-mm-dd (actually I don't, I just need to sort it and that format is
the most foolproof way of sorting). This all needs to be done in VBA as
it's part of a bigger project that allows a bunch of data collation at
once. The other problem is that the input sheet can be quite large
(150,000+ rows). So, while I could parse through each row of data and
change it around to the way I need, this would be horrifically slow and is
NOT an option.
Currently I'm using this bit of code to format the date to yyyy-mm-dd:
inputGADRSheet.Columns(7).NumberFormat = "yyyy-mm-dd"
But, Excel outsmarts me and assumes that the date format of the column is
originally in the US format (mm/dd/yyyy) which messes everything up and
half of the values in the column don't meet that requirement (days above
the 12th) so they don't get formatted at all. Is there any way to tell
Excel what format the current data is in? That way it won't just assume
that it's in the US date format...
Is the solution to change my Excel region to the UK. I assume this could
be done using VBA, but it seems risky...

No comments:

Post a Comment