【发布时间】:2021-06-22 22:08:27
【问题描述】:
对于 200k+ 行的列表,我有 4 个日期值按重要性降序排列。 重要性顺序为 date1 > date2 > date3 > date4。有时,日期值中没有值或单个空格字符串。如果发生这种情况,我将需要进入下一个最重要的日期。 date4 将始终是正确的日期值。
我在下面有一个简单的函数,它返回所需的值,但我想知道是否有任何方法可以让它更快?我的列表很容易膨胀到 500K+ 行,并且会占用大量时间
Function getConEndDate(date1 As Date, date2 As Date, date3 As Date, date4 As Date) As Date
Dim endDate As Date
If Len(date1) > 2 Then
endDate = date1
ElseIf Len(date2) > 2 Then
endDate = date2
ElseIf Len(date3) > 2 Then
endDate = date3
Else
endDate = date4 + 30
End If
getConEndDate = endDate
End Function
【问题讨论】:
-
这里有一些根本错误:您的函数接受
Date类型的参数。Len(AnyDate)将始终 > 2。如果您传递空单元格,它将转换为“00:00:00”,如果您传递单个空格字符串,则会出现运行时错误。此外,该函数本身很快(调用它 1,000,000 次有效日期在我的硬件上运行时间