vba,excel:返回此字符串数组中的最早日期值 [英] vba, excel : returning the earliest date value in this array of string
本文介绍了vba,excel:返回此字符串数组中的最早日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在编码方面遇到一些问题,不知道在哪里修复:
i'm having some issues with the coding and not sure where to fix this:
我希望BronzeDate返回我的数组中最早的日期。
I would like the BronzeDate to return the earliest date found in my array.
这是打印输出的示例:
Possible Bronze Date : 6/6/2011
Possible Bronze Date : 10/5/2011
Possible Bronze Date : 10/5/2011
Possible Bronze Date : 12/5/2011
Possible Bronze Date : 10/5/2011
Possible Bronze Date : 6/6/2011
Possible Bronze Date : 11/5/2011
Possible Bronze Date : 1/16/2012
Possible Bronze Date : 6/6/2011
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
Possible Bronze Date :
[BRONZE] 0
编码:
Dim Bronze(1 To 100) As String
...
Dim c As Integer
c = 1
Do Until c = 20
Debug.Print " Possible Bronze Date : " & Bronze(c)
c = c + 1
Loop
' EXTRACT THE MIN VALUES
Dim BronzeDate As String
BronzeDate = Application.WorksheetFunction.Min(Bronze)
' PRINT OUT VALUE FOR EACH DATES
Debug.Print " [BRONZE] " & BronzeDate
推荐答案
我相信你别无选择,字符串日期。
I believe you have no choice but to individually convert the string dates.
我已经测试过此代码以输出正确的日期。注意我将数组中的中间结尾的日期切换成小端,所以我的Excel版本会正确处理它们。
I have tested this code to output the correct date. Note I have switched the middle endian dates in your array to little endian so my version of Excel will process them correctly.
Sub ExtractMinDate()
Dim Bronze() As Variant
Dim DateCrnt As Date
Dim DateMin As Date
Dim InxBronze As Long
Bronze = Array("6/6/2011", "5/10/2011", "5/10/2011", "1/12/2011", "5/10/2011", _
"6/6/2011", "5/11/2011", "16/1/2012", "5/6/2011")
DateMin = 0
For InxBronze = LBound(Bronze) To UBound(Bronze)
If IsDate(Bronze(InxBronze)) Then
DateCrnt = Bronze(InxBronze)
If DateMin = 0 Or DateMin > DateCrnt Then
DateMin = DateCrnt
End If
End If
Next
Debug.Print DateMin
End Sub
这篇关于vba,excel:返回此字符串数组中的最早日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文