|
参与一下。。。- Sub ykcbf() '//2024.5.21
- Dim arr, d
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("数据来源")
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- arr = .[a1].Resize(r, 12)
- End With
- ReDim brr(1 To 10000, 1 To UBound(arr, 2))
- For i = 1 To UBound(arr)
- s = CStr(arr(i, 4))
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- b = [{1,2,3,4,5,6,7,9,10,11,12}]
- bb = [{4,5,6,7,11}]
- On Error Resume Next
- For Each k In d.keys
- ReDim Sum(1 To 2)
- For Each kk In d(k).keys
- m = m + 1
- For j = 1 To UBound(b)
- brr(m, j) = arr(kk, b(j))
- Next
- Sum(1) = Sum(1) + brr(m, 8)
- Sum(2) = Sum(2) + brr(m, 9)
- Next
- m = m + 1
- brr(m, 1) = "合计"
- For x = 1 To UBound(bb)
- brr(m, bb(x)) = brr(m - 1, bb(x))
- Next
- brr(m, 8) = Sum(1)
- brr(m, 9) = Sum(2)
- Next
- With Sheets("VBA结果")
- .UsedRange.Cells.Interior.ColorIndex = 0
- .Columns(4).NumberFormatLocal = "@"
- .[a2].Resize(m, 11) = brr
- For i = 2 To m + 1
- If .Cells(i, 1) = "合计" Then
- .Cells(i, 1).Resize(1, 11).Cells.Interior.ColorIndex = 6
- End If
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|