請在需要幫助時使用可能會複雜的公式, 重述,此表具有用戶名,間隔,聊天開始時間和聊天結束時間, 我需要導出免費時間,代理沒有任何聊天時間,因此該試劑可以具有2或3個聊天一次,計算開始和結束時間之間的加布數據
我用下面的代碼以獲得端部之間的持續時間之間的間隙,並開始聊天:
Option Explicit
Function DataGap(NameRange As Range, xName As String, StartRange As Range, EndRange As Range, StartTime As Date, Optional EndTime As Date) As Date
Dim GapRange As Range
Dim ShiftRange As Range
'how many seconds in a day?
Const xConv As Long = 86400
Dim intRange As Range
Dim i As Long
Dim missingCells As Long
If EndTime = 0 Then
'Calculate end of interval
EndTime = StartTime + TimeValue("0:15:00")
End If
'Build shift range
Set ShiftRange = Range(Cells(StartTime * xConv, 1), Cells(EndTime * xConv, 1))
'Build filled range
For i = 1 To NameRange.Cells.Count
If NameRange.Cells(i).Value = xName Then
If GapRange Is Nothing Then
Set GapRange = Range(Cells(StartRange.Cells(i) * xConv, 1), Cells(EndRange.Cells(i) * xConv, 1))
Else
Set GapRange = Union(GapRange, Range(Cells(StartRange.Cells(i) * xConv, 1), Cells(EndRange.Cells(i) * xConv, 1)))
End If
End If
Next i
If Not GapRange Is Nothing Then
Set intRange = Intersect(GapRange, ShiftRange)
End If
If intRange Is Nothing Then
missingCells = ShiftRange.Cells.Count - 1
Else
missingCells = ShiftRange.Cells.Count - intRange.Cells.Count
End If
DataGap = missingCells/xConv
End Function
在回顧一下,這片獲得免費的時間(GAP)之間的「上次」與「開始時間),但不完全,有什麼出錯,我不能得到它
如圖
彩色單元格指的是發生錯誤的值。由於UDF結果0返回,而他們是自由時間按「上次」之間的差距與「開始時間)
非常感謝,