|
加上合并单元格- Sub ykcbf() '2024.8.30
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("Sheet1")
- r = .Cells(Rows.Count, 1).End(3).Row
- zrr = .[a1].Resize(r, 10)
- For i = 4 To UBound(zrr)
- s = zrr(i, 1): ss = zrr(i, 2)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- If Not d(s).exists(ss) Then Set d(s)(ss) = CreateObject("Scripting.Dictionary")
- d(s)(ss)(i) = i
- Next
- End With
- ReDim brr(1 To 10000, 1 To UBound(zrr, 2))
- b = [{1,2,3,5,10,7,4,6,8,9}]
- On Error Resume Next
- With Sheets("Sheet2")
- .Columns(2).NumberFormatLocal = "@"
- .UsedRange.Offset(3).Interior.ColorIndex = 0
- .UsedRange.Offset(3).Clear
- M = 3
- For Each k In d.keys
- s1 = 0: s2 = 0: s3 = 0
- For Each kk In d(k).keys
- For Each kkk In d(k)(kk).keys
- M = M + 1
- For j = 1 To UBound(b)
- .Cells(M, j) = zrr(kkk, b(j))
- Next
- .Cells(M, 7) = .Cells(M, 7) / 10000
- .Cells(M, 9) = .Cells(M, 9) / 10000
- .Cells(M, 10) = .Cells(M, 10) / 10000
- s1 = s1 + .Cells(M, 7)
- s2 = s2 + .Cells(M, 9)
- s3 = s3 + .Cells(M, 10)
- Next
- Next
- M = M + 1
- .Cells(M, 1) = k & " 汇总"
- .Cells(M, 7) = s1: .Cells(M, 9) = s2: .Cells(M, 10) = s3
- .Cells(M, 1).Resize(, 10).Interior.ColorIndex = 8
- Next
- Set rng = .[a4].Resize(M - 3, 3)
- With rng
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- zr = Array(1)
- Call hb(4, 10, 1, zr)
- zr = Array(2, 3)
- Call hb(4, 10, 2, zr)
- .[a4].Resize(M - 3, 10).Borders.LineStyle = 1
- End With
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|