|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。
- Sub ykcbf() '//2024.6.20
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("数据")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 15)
- End With
- ReDim brr(1 To 1000, 1 To 1)
- For i = 2 To UBound(arr)
- s = arr(i, 4)
- If Not d1.exists(s) Then
- m = m + 1
- d1(s) = m
- brr(m, 1) = s
- End If
- s = arr(i, 4) & "|" & arr(i, 8)
- If Not d.exists(s) Then
- d(s) = Array(1, arr(i, 14))
- Else
- t = d(s)
- t(0) = t(0) + 1
- t(1) = t(1) + arr(i, 14)
- d(s) = t
- End If
- Next
- With Sheets("结果")
- .UsedRange.Offset(2).Clear
- .[a3].Resize(m, 1) = brr
- bt = 2
- arr = .Range("a1:ab" & m + bt)
- On Error Resume Next
- For i = 3 To UBound(arr)
- sum1 = 0: sum2 = 0
- For j = 2 To UBound(arr, 2) - 3 Step 3
- s = arr(i, 1) & "|" & arr(1, j)
- If d.exists(s) Then
- arr(i, j) = d(s)(0)
- arr(i, j + 1) = d(s)(1)
- arr(i, j + 2) = Application.WorksheetFunction.Round(arr(i, j + 1) / arr(i, j), 2)
- sum1 = sum1 + arr(i, j)
- sum2 = sum2 + arr(i, j + 1)
- End If
- Next
- arr(i, UBound(arr, 2) - 2) = sum1
- arr(i, UBound(arr, 2) - 1) = sum2
- arr(i, UBound(arr, 2)) = Application.WorksheetFunction.Round(sum2 / sum1, 2)
- Next
- .Range("a1:ab" & m + bt) = arr
- .Cells(m + bt + 1, 1) = "合计"
- r = .Cells(Rows.Count, 1).End(3).Row
- For j = 2 To UBound(arr, 2) Step 3
- .Cells(r, j) = Application.Sum(.Cells(3, j).Resize(m))
- .Cells(r, j + 1) = Application.Sum(.Cells(3, j + 1).Resize(m))
- .Cells(r, j + 2) = Application.WorksheetFunction.Round(.Cells(r, j + 1) / .Cells(r, j), 2)
- Next
- With .Range("a1:ab" & m + bt + 1)
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|