|
Sub ykcbf() '//2024.5.13
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
arr = Sheets("分包人").UsedRange
For i = 2 To UBound(arr)
s = arr(i, 1)
If s <> Empty Then d1(s) = ""
Next
With Sheets("表一")
r = .Cells(Rows.Count, 2).End(3).Row
arr = .[A1].Resize(r, 8)
For Each k In d1.keys
For i = 3 To UBound(arr)
If Val(arr(i, 1)) = 0 Then
If InStr(arr(i, 2), k) Then
s = arr(i, 2)
If Not d.exists(k) Then Set d(k) = CreateObject("Scripting.Dictionary")
d(k)(s) = Array(arr(i, 4), arr(i, 5), arr(i, 6), arr(i, 7))
End If
End If
Next
Next
End With
ReDim brr(1 To 1000, 1 To 6)
For Each k In d.keys
Sum1 = 0
Sum2 = 0
Sum3 = 0
Sum4 = 0
For Each kk In d(k).keys
m = m + 1
brr(m, 1) = kk
brr(m, 2) = k
crr = d(k)(kk)
brr(m, 3) = crr(0)
brr(m, 4) = crr(1)
brr(m, 5) = crr(2)
brr(m, 6) = crr(3)
Sum1 = Sum1 + brr(m, 3)
Sum2 = Sum2 + brr(m, 4)
Sum3 = Sum3 + brr(m, 5)
Sum4 = Sum4 + brr(m, 6)
Next
m = m + 1
brr(m, 2) = k
brr(m, 3) = Sum1
brr(m, 4) = Sum2
brr(m, 5) = Sum3
brr(m, 6) = Sum4
Next
With Sheets("分类汇总表")
.[b2:g1000] = ""
.[b2].Resize(m, 6) = brr
End With
Set d = Nothing
Set d1 = Nothing
MsgBox "OK!"
End Sub
|
|