Vba 计算开始和结束持续时间之间的gab数据
求你了,我需要一个可能很复杂的公式, 在概述中,此表包含用户名、时间间隔、聊天开始时间和聊天结束时间, 我需要导出代理没有任何聊天时间的空闲时间,因此代理可能一次有2或3次聊天 我使用以下代码来获取聊天结束和开始之间的持续时间间隔:Vba 计算开始和结束持续时间之间的gab数据,vba,excel,Vba,Excel,求你了,我需要一个可能很复杂的公式, 在概述中,此表包含用户名、时间间隔、聊天开始时间和聊天结束时间, 我需要导出代理没有任何聊天时间的空闲时间,因此代理可能一次有2或3次聊天 我使用以下代码来获取聊天结束和开始之间的持续时间间隔: Option Explicit Function DataGap(NameRange As Range, xName As String, StartRange As Range, EndRange As Range, StartTime As Date, Opt
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
总而言之,这张表得到了“最后一次”和“开始时间”之间的空闲时间(间隔),但不是全部,有些地方出了问题,我无法得到它
如图所示
彩色单元格引用了错误的发生值。因为UDF结果返回0,而根据“上次时间”与“开始时间”之间的间隔,它们是空闲时间)
非常感谢,我不知道您为什么要为此创建宏。这可以通过一个简单的公式来实现。使用以下步骤:
代理名称
,第二级为就诊时间
。这将为您提供一个列表,其中按顺序列出每个代理的所有访问时间列E
之后插入一列。我们的新专栏现在将是专栏F
。将此列命名为空闲时间
列F
的第一个单元格(即单元格F2
)中粘贴公式-=IF(E2是的,关于使用公式对列进行排序,你是对的,但问题是我在工作表中有大量数据,在排序或应用计算时,工作簿需要很长的过程才能计算出结果,因此我使用VBA