试试看,处理本例6万行数据在我的机器上用时约0.7秒:- Sub cbtaja()
- Dim arr, brr, d, d2, i&, j&, k&, zl&, r&, h&, l&, p&, t#, ghgx$, tmp
- t = Timer
- Set d = CreateObject("scripting.dictionary")
- arr = Sheet2.Range("A1").CurrentRegion
- r = UBound(arr)
- ReDim brr(1 To 5000) '假设工人人数5000以内
- ReDim crr(1 To 5000, 1 To 256) '假设工序256以内
- For i = 2 To r
- arr(i, 2) = Format(arr(i, 2), String(8, "0"))
- ghgx = arr(i, 2) & arr(i, 11)
- If Not d.Exists(arr(i, 2)) Then
- h = h + 1
- d(arr(i, 2)) = h
- brr(h) = 2
- d(ghgx) = 2
- crr(h, 1) = arr(i, 2)
- crr(h, 2) = Array(arr(i, 8), arr(i, 11), arr(i, 14))
- Else
- p = d(arr(i, 2))
- If d.Exists(ghgx) Then
- l = d(ghgx)
- tmp = crr(p, l)
- tmp(2) = tmp(2) + arr(i, 14)
- If InStr(tmp(0), arr(i, 8)) = 0 Then tmp(0) = tmp(0) & "/" & arr(i, 8)
- crr(p, l) = tmp
- Else
- l = brr(p) + 1
- d(ghgx) = l
- If zl < l Then zl = l
- brr(p) = l
- crr(p, l) = Array(arr(i, 8), arr(i, 11), arr(i, 14))
- End If
- End If
- Next
- For i = 1 To h
- For j = 2 To brr(i)
- If IsArray(crr(i, j)) Then
- If InStr(crr(i, j)(0), "/") > 0 Then crr(i, j)(0) = "(" & crr(i, j)(0) & ")"
- crr(i, j) = Join(crr(i, j), " ") & "件"
- End If
- Next
- Next
- Sheet1.Range("A2").Resize(h, zl) = crr
- MsgBox Timer - t
- End Sub
复制代码 |