有誰知道如何獲取Microsoft Excel中行的最早日期。每行不存在可預測的列數,並且除日期之外還有值需要忽略的值。它可以用Excel公式或VBA完成。MS Excel:查找混合內容行中的最早日期
有沒有人有任何建議?
現在我用這個快速和骯髒的VBA函數,但是當我加載新的輸入數據(大約200行100列)一個消息框想出說,Excel沒有足夠的資源來處理我的變化。
' returns smallest date on row
Public Function getSmallestDateFromRow(r As Integer, sheetName As String) As Date
Dim toReturn As Date
Dim rng As Range
Dim scanToColumn As Integer
Dim c As Integer
Dim tmp As Variant
Set rng = Sheets(sheetName).Cells.Find("*", [a1], , , xlByColumns, xlPrevious) 'is this inefficient?
scanToColumn = rng.Column
toReturn = #12/12/2100#
For c = 1 To scanToColumn
tmp = Sheets(sheetName).Cells(r, c).Value
If (IsDate(tmp)) Then
If (toReturn = Null) Then
toReturn = tmp
ElseIf (toReturn > tmp) Then
toReturn = tmp
End If
End If
Next c
If (toReturn = #12/12/2100#) Then
toReturn = 0
End If
getSmallestDateFromRow = toReturn
End Function
這是一個Worksheet函數/ UDF嗎?或另一個宏調用的函數? – NickSlash