将日期转换为String时遇到问题。一般来说,我不知道如何使用VBA将日期转换为数字。标有“OVERFLOW”的行中有溢出。为什么? PS:数组的第一个值" daty"是" 2018-03-26"。
Sub Sortuj_daty()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.Worksheets(1)
Dim i As Long
Dim daty(1 To 10) As String
Dim daty_int(1 To 10) As Long
Dim daty_uporzadkowane(1 To 10) As String
For i = 1 To 10
daty(i) = ws.Cells(i, 1).Value
daty_int(i) = CInt(CDate(Format(daty(i), "yyyy-mm-dd"))) 'OVERFLOW
Next i
For j = 1 To 10
daty_uporzadkowane(j) = Application.WorksheetFunction.Small(daty_int, j)
ws.Cells(j, 2) = daty_uporzadkowane(j)
Next j
End Sub