如何从日期数组中找到最早的MMMYY?

时间:2013-05-10 10:43:26

标签: excel excel-vba vba

有谁知道如何从以下形式的数组中找到最早的MMMYY(参见专栏K)。

注意:日期不按升序排序。

enter image description here

代码:

Sub outputfile()
'Capture the contract no. in ContractNo() array
Dim ContractNo() As String
'Capture the project title in ProjectTitle() array
Dim ProjectTitle() As String
'Capture the contract start in ContractStart() array
Dim ContractStart() As Date
'Capture the contract end in ContractEnd() array
Dim ContractEnd() As Date

'Capture ASPQ Cement in ASPQC() array
Dim ASPQC() As Double
'Capture ASP Sand in ASPQS() array
Dim ASPQS() As Double
'Capture ASP Aggregate in ASPQA() array
Dim ASPQA() As Double

i = 2
Do Until IsEmpty(Cells(i, 1).Value)
i = i + 1
Loop

ReDim ContractNo(1 To i - 2)
ReDim ProjectTitle(1 To i - 2)
ReDim ContractStart(1 To i - 2)
ReDim ContractEnd(1 To i - 2)
ReDim ASPQC(1 To i - 2)
ReDim ASPQS(1 To i - 2)
ReDim ASPQA(1 To i - 2)

For i = 1 To UBound(ContractNo, 1)
ContractNo(i) = Cells(i + 1, 1).Value
ProjectTitle(i) = Cells(i + 1, 2).Value
ContractStart(i) = Cells(i + 1, 11).Value
ContractEnd(i) = Cells(i + 1, 12).Value
ASPQC(i) = Cells(i + 1, 14).Value
ASPQS(i) = Cells(i + 1, 15).Value
ASPQA(i) = Cells(i + 1, 16).Value
Next i

End sub

1 个答案:

答案 0 :(得分:3)

我认为最好的是细胞中的内置配方。

=TEXT(MIN(K:K), "MMMYY") 
相关问题