2013-05-10 54 views
0

有誰知道我可以從下面的表格中找到最早的MMMYY(參見K欄)。如何從日期數組中找到最早的MMMYY?

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

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 
+0

我必須管理員我不知道VBA,但不是像「min()」方法那樣嗎? – 2013-05-10 10:46:48

+0

我想過使用min()函數,但想知道是否有更好的方法。 :) – 2013-05-10 10:47:35

+1

那麼,如果有一個工作內置函數,爲什麼你甚至會認爲你可以做得更好?現在我不是說這是行得通的,但你似乎同意它是... – 2013-05-10 10:50:39

回答

3

我認爲最好是建在公式中的單元格。

=TEXT(MIN(K:K), "MMMYY")  
相關問題