Function gettime(t)
Randomize
If VBA.TypeName(t) = "String" Then tmp = TimeValue(t) Else tmp = t
gettime = Format(tmp - Rnd * 20 / 24 / 60, "hh:mm")
End Function
使用方法
=gettime("08:00")
或
=gettime($B$1)
(假设B1中填着08:00
下面是例子代码:
Option Explicit
Sub test()
MsgBox getTime(#8:00:00 AM#)
End Sub
Function getTime(t As Date) As Date
getTime = t - Int(1 + Rnd * 19) / 60 / 24
End Function