我正在尝试编写一些代码,以便获取两个日期之间的每一天,并创建一个列表。我的代码如下:
Sub DateList()
Dim start As Date
start = DateValue("1/1/2001")
Dim finish As Date
finish = DateValue("1/1/2002")
Dim datearray()
ReDim datearray(finish - start + 1)
For i = 0 To finish - start
datearray(i) = start + i
Next
Range("A1:A" & UBound(datearray) + 1) = WorksheetFunction.Transpose(datearray)
End Sub
然而,结果看起来像这样:
1/01/2001
1/02/2001
1/03/2001
1/04/2001
1/05/2001
1/06/2001
1/07/2001
1/08/2001
1/09/2001
1/10/2001
1/11/2001
1/12/2001
13/01/2001
14/01/2001
15/01/2001
16/01/2001
17/01/2001
18/01/2001
19/01/2001
20/01/2001
21/01/2001
22/01/2001
23/01/2001
24/01/2001
25/01/2001
26/01/2001
27/01/2001
28/01/2001
29/01/2001
30/01/2001
31/01/2001
2/01/2001
2/02/2001
2/03/2001
....
到第13行时就会出现问题。似乎在某个地方切换了dd/mm/yyyy
格式和mm/dd/yyyy
格式。我做错了什么?