|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Function Timex(rng1 As Range, rng2 As Range, Optional n As Long = 0) As String
Dim ar(), br()
ar = rng1
br = rng2
If ar(1, 2) < br(1, 1) Or ar(1, 1) > br(1, 2) Then
If n = 0 Then Timex = "相离"
If n = 1 Then Timex = Format(ar(1, 2), "hh:mm:ss") & "~" & Format(br(1, 1), "hh:mm:ss")
If n = 2 Then Timex = Format((br(1, 1) - ar(1, 2)), "hh:mm:ss")
If n = 3 Then Timex = Format((br(1, 1) - ar(1, 2)) * 86400, "0")
ElseIf ar(1, 2) = br(1, 1) Or ar(1, 1) = br(1, 2) Then
If n = 0 Then Timex = "相临"
If n = 1 Or n = 2 Or n = 3 Then Timex = "-"
Else
If n = 0 Then Timex = "相交"
If n = 1 Then Timex = Format(br(1, 1), "hh:mm:ss") & "~" & Format(ar(1, 2), "hh:mm:ss")
If n = 2 Then Timex = Format(ar(1, 2) - br(1, 1), "hh:mm:ss")
If n = 3 Then Timex = Format((ar(1, 2) - br(1, 1)) * 86400, "0")
End If
End Function |
|