|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。- Sub ykcbf() '//2024.11.24
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("数据源")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(1, Columns.Count).End(1).Column
- arr = .[a1].Resize(r, c)
- End With
- ReDim brr(1 To r, 1 To 100)
- For i = 2 To UBound(arr)
- s1 = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
- If Not d.exists(s1) Then
- m = m + 1
- d(s1) = m
- brr(m, 1) = m
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(i, 3)
- brr(m, 4) = arr(i, 5)
- brr(m, 5) = arr(i, 6)
- End If
- For j = 7 To UBound(arr, 2)
- s = s1 & "|" & arr(i, 4) & "|" & arr(1, j)
- d(s) = d(s) + arr(i, j)
- Next
- Next
- With Sheets("效果")
- .UsedRange.Offset(2).ClearContents
- .[a3].Resize(m, 5) = brr
- arr = .UsedRange
- For i = 3 To UBound(arr)
- Sum = 0
- s1 = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
- For j = 6 To UBound(arr, 2) Step 5
- For x = 1 To 3
- s = s1 & "|" & arr(2, j + x - 1) & "|" & arr(1, j)
- arr(i, j + x - 1) = d(s)
- Sum = Sum + arr(i, j + x - 1)
- Next
- arr(i, j + 4) = Sum + arr(i, j + 3)
- Next
- Next
- .UsedRange = arr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|