|
|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub ykcbf() '//2025.10.30
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- arr = Sheets("数据").Range("a1").CurrentRegion.Value
- ReDim brr(1 To UBound(arr), 1 To 5)
- On Error Resume Next
- For i = 2 To UBound(arr)
- If Len(arr(i, 1) & "") Then
- s = arr(i, 3) & " " & arr(i, 6)
- d(s) = d(s) + Val(arr(i, 8))
- End If
- Next
- k = d.keys: t = d.items
- For x = 0 To d.Count - 1 Step 2
- m = m + 1
- brr(m, 1) = Split(k(x))(0)
- brr(m, 2) = Split(k(x))(1)
- brr(m, 3) = t(x)
- brr(m, 4) = Split(k(x + 1))(1)
- brr(m, 5) = t(x + 1)
- Next
- With Sheets("汇总")
- .UsedRange.Offset(1).Clear
- Set Rng = .[a2].Resize(m, 5)
- Rng.Value = brr
- Rng.Borders.LineStyle = 1
- Rng.Sort Rng.Columns(1), 1
- For i = m + 1 To 2 Step -1
- Set Rng = .Cells(i, 1)
- If Rng.Value = Rng.Offset(-1).Value Then
- With Rng.Offset(-1).Resize(2)
- .Merge
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End If
- Next i
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|