Excel中作业并发性的计算
我需要计算excel中作业的并发性。我有作业的开始时间和结束时间 在下图中,我希望结果为3,因为这是最大并发性 我尝试了许多COUNTIFS公式,但没有得到正确的结果 数据样本Excel中作业并发性的计算,excel,Excel,我需要计算excel中作业的并发性。我有作业的开始时间和结束时间 在下图中,我希望结果为3,因为这是最大并发性 我尝试了许多COUNTIFS公式,但没有得到正确的结果 数据样本 下面是它在VBA中的外观: Option Explicit Sub UsingArrayList() Dim sht As Worksheet Dim FirstRow, LastRow As Long Set sht = ActiveSheet Dim arrival As O
下面是它在VBA中的外观:
Option Explicit
Sub UsingArrayList()
Dim sht As Worksheet
Dim FirstRow, LastRow As Long
Set sht = ActiveSheet
Dim arrival As Object, departure As Object
Dim i As Long, j As Long, n As Long
Dim guests_in As Long, max_guests As Long, time As Double
Set arrival = CreateObject("System.Collections.ArrayList")
Set departure = CreateObject("System.Collections.ArrayList")
With sht
' Copy ranges into arrival and departure arrays
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = FirstRow To LastRow
arrival.Add (.Cells(i, 1).Value)
departure.Add (.Cells(i, 2).Value)
Next i
End With
' Sort arrival and departure arrays
arrival.Sort
departure.Sort
' guests_in indicates number of guests at a time
guests_in = 1
max_guests = 1
time = arrival.Item(0)
i = 1
j = 0
n = arrival.Count
' Similar to merge in merge sort to process
' all events in sorted order
While (i < n And j < n)
' If next event in sorted order is arrival,
' increment count of guests
If (arrival.Item(i) <= departure.Item(j)) Then
guests_in = guests_in + 1
' Update max_guests if needed
If (guests_in > max_guests) Then
max_guests = guests_in
time = arrival.Item(i)
End If
i = i + 1 'increment index of arrival array
Else ' If event is departure, decrement count
' of guests.
guests_in = guests_in - 1
j = j + 1
End If
Wend
Debug.Print ("Max concurrency=" & max_guests)
Debug.Print ("at time " & time)
Debug.Print ("at time " & Application.Text(time, "hh:mm:ss"))
End Sub
选项显式
Sub-UsingArrayList()
将sht变暗为工作表
第一排昏暗,最后一排一样长
设置sht=ActiveSheet
到达作为对象,离开作为对象
暗i为长,j为长,n为长
昏暗的客人进来的时间一样长,最大的客人进来的时间一样长,时间一样长
Set arrival=CreateObject(“System.Collections.ArrayList”)
Set department=CreateObject(“System.Collections.ArrayList”)
用短发
'将范围复制到到达和离开数组中
第一行=2
LastRow=.Cells(.Rows.Count,“A”).End(xlUp).Row
对于i=第一行到最后一行
添加(.Cells(i,1).Value)
添加(.i,2.Value单元格)
接下来我
以
'对到达和离开数组进行排序
到达,分类
出发,分类
“guests_in”表示一次的来宾数
宾客人数=1
最大客人数=1
时间=到达。项目(0)
i=1
j=0
n=到达。计数
'类似于要处理的合并排序中的合并
'按排序的顺序排列所有事件
而(i If(到货。项目(i)您能否提供一个您尝试过的公式,公式的结果是什么,以及结果不正确的原因?我已在描述中添加了另一个图像。红线是我要计算并发性的作业。这些作业中有很多。不幸的是,这计算了太多的作业,因为有些作业包含在作业“red”中,但不是共同的n彼此当前是否正确,从计算链接判断,您有近一百万行数据?我们需要查看您的数据样本以更好地了解它。我已在Post中的表格中添加了数据图片。您能提供更大的图片吗?正如@TomSharpe所说,看起来您有一百万行数据。w排在哪一排?