请在需要帮助时使用可能会复杂的公式, 重述,此表具有用户名,间隔,聊天开始时间和聊天结束时间, 我需要导出免费时间,代理没有任何聊天时间,因此该试剂可以具有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返回,而他们是自由时间按“上次”之间的差距与“开始时间)
非常感谢,