我正在尝试计算在Excel中完成分析所需的时间。我使用DateDiff来计算所需的秒数,然后尝试将其格式化为小时、分钟和秒。
我的代码如下,在以下行中导致溢出错误:
dTime = dTime / (60 * 60 * 24)
你知道我做错了什么吗?
Dim dTime As Long
Dim startTime, endTime As Date
startTime = Now() ' at the start of the analysis
endTime = Now() ' at the end of the analysis
dTime = DateDiff("s", startTime, endTime)
dTime = dTime / (60 * 60 * 24) 'convert seconds into days
StatusBox.Value = "Analysis completed in " & Format(dTime, "hh:mm:ss") & "."
startTime
声明为变量。您需要明确指出:Dim startTime as Date
。 - kaybee99