0

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...

4

1 回答 1

1

如果您的数据已经在 Excel 列中,则无法重新解释这些值:Excel 日期值是(内部)数字,1表示 1900-01-01。在 Excel 对数据进行(错误)解释后,就没有回头路了。

问题是:您从哪里获得输入数据表?如果日期输入正确,则可以毫无问题地重新格式化并且不影响排序(仅取决于日期的数值)。如果您的数据来自文本文件(可能是 .csv 类型),请务必将 ii 读取为文本并使用 Excel 工作表函数或 VBA 来解释这些值。

于 2013-08-08T15:10:41.103 回答