EXCEL计数IFS代码日期和时间间隔。
使用公式的图像示例:

如何构建G列中的计数:AB按小时8-9,9-10等,查看E列中的日期和使用日期范围从时间开始到超时之间的计数时间?
发布于 2015-11-10 21:40:19
工作表的日期和日期的性质可以跨越多天,因此这将使您的CountIf公式相当复杂。因为你必须把A和B,以及C和D结合起来,才能充分理解它所指的日期。
您应该创建一个自定义的VBA函数,否则使用excel的本地函数它会变得非常复杂。
步骤1)将第1列G更改为早上7:00:00,然后将其扩展到AD列(一直到上午6:00)
步骤2)点击Alt + F11并在左侧插入一个新模块。复制并粘贴此代码:
Public Function CountTimeSlots(ByVal DateIn As Range, ByVal TimeIn As Range, _
ByVal DateOut As Range, ByVal TimeOut As Range, _
ByVal DateMatch As Range, ByVal TimeMatch As Range) As Integer
Dim start As Date
Dim finish As Date
Dim match As Date
Dim i As Integer
'Initialize to 0
CountTimeSlots = 0
For i = 1 To DateIn.Rows.Count
'Combine Column A and B into a singular date
start = CDate(DateIn.Cells(i, 1).Value) + CDate(TimeIn.Cells(i, 1).Value)
'Combine Column C and D into a singular date
finish = CDate(DateOut.Cells(i, 1).Value) + CDate(TimeOut.Cells(i, 1).Value)
'Combine Column E and the vertical time stamp; Note these Match values are hardcoded to one cell
match = CDate(DateMatch.Cells(1, 1).Value) + CDate(TimeMatch.Cells(1, 1).Value)
'If the match value falls between the In and Out time, increment by 1
If (match >= start And match <= finish) Then
CountTimeSlots = CountTimeSlots + 1
End If
Next i
End Function步骤3)在单元格G2中使用公式。然后将其扩展到右侧和向下(或向下然后向右)。
=CountTimeSlots($A$2:$A$7,$B$2:$B$7,$C$2:$C$7,$D$2:$D$7,$E2,G$1)(第4步)我建议您交换E列和F列,或者删除列F。乍一看,E列中的日期与and列是分开的,这并不是很直观。
https://stackoverflow.com/questions/33636892
复制相似问题