|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。
- Sub ykcbf2() '//2024.5.9 全表自动生成
- Dim arr, brr, d
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Sheets("原始数据")
- r = .Cells(Rows.Count, 2).End(3).Row
- arr = .Range("a1").Resize(r, 5)
- End With
- ReDim brr(1 To UBound(arr), 1 To 100)
- brr(1, 1) = arr(1, 1)
- m = 1: n = 1
- For i = 2 To UBound(arr) - 1
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = s
- End If
- r = d(arr(i, 1))
- For j = 2 To UBound(arr, 2)
- s = arr(1, j)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = arr(1, j)
- End If
- c = d(arr(1, j))
- brr(r, c) = brr(r, c) + arr(i, j)
- Next
- Next
- With Sheets("数据汇总")
- .UsedRange.Clear
- .[a1].Resize(1, n + 1).Interior.Color = 49407
- .[a2].Resize(m - 1, 1).Interior.Color = 5296274
- With .[a1].Resize(m + 1, n + 1)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- .Cells(1, n + 1) = "合计"
- For i = 2 To m + 1
- .Cells(i, n + 1) = Application.WorksheetFunction.Sum(.Cells(i, 2).Resize(1, 4))
- Next
- m = m + 1
- .Cells(m, "a") = "合计"
- .Cells(m, "b").Resize(1, n).FormulaR1C1 = "=SUM(R2C:R" & "[-1]C)"
- End With
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
|