- Sub 按分包人汇总()
- Dim arr, brr, i, j, r, d
- Set d = CreateObject("scripting.dictionary")
- arr = Sheet2.UsedRange
- For i = 2 To UBound(arr)
- sa = arr(i, 1)
- d(sa) = ""
- Next
- With Sheet1
- r = .Cells(Rows.Count, 2).End(xlUp).Row
- brr = .Range("a2:g" & r)
- End With
- ReDim crr(1 To UBound(brr), 1 To 7)
- For j = 2 To UBound(brr)
- If InStr(brr(j, 2), "月") = 0 Then
- For Each k In d.keys
- If InStr(brr(j, 2), k) Then
- n = n + 1
- crr(n, 1) = ""
- crr(n, 2) = brr(j, 2)
- crr(n, 3) = k
- crr(n, 4) = brr(j, 4)
- crr(n, 5) = brr(j, 5)
- crr(n, 6) = brr(j, 6)
- crr(n, 7) = brr(j, 7)
- End If
- Next
- End If
- Next
- With Sheet4
- .UsedRange.Offset(1).ClearContents
- .[a2].Resize(n, 7) = crr
- Set Rng = Range("b2").Resize(n, 6)
- Rng.Sort [c1], Header:=xlYes
- r = .Cells(Rows.Count, 2).End(xlUp).Row
- For j = r To 2 Step -1
- For i = j - 1 To 1 Step -1
- If .Cells(j, 3) <> .Cells(i, 3) Then
- .Rows(j + 1).Insert
- .Cells(j + 1, 3) = .Cells(j, 3)
- .Cells(j + 1, 4) = Application.Sum(Range(.Cells(i + 1, 4), .Cells(j, 4)))
- j = i
- End If
- Next
- Next
- End With
- End Sub
复制代码 |