|
改一下。。。
- Sub ykcbf() '//2024.8.13 排重汇总,标题行按B列内容写入
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- ReDim brr(1 To 10000, 1 To 100)
- m = 1
- brr(1, 1) = "客户"
- On Error Resume Next
- With Sheets("数据源")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- n = 1
- For i = 2 To UBound(arr)
- 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))
- s = arr(i, 2)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = s
- End If
- c = d(arr(i, 2))
- brr(r, c) = brr(r, c) + arr(i, 8)
- Next
- n = n + 1
- brr(1, n) = "总计"
- With Sheets("统计查看")
- .UsedRange.Offset(1).Clear
- .[a2].Resize(1, n).Interior.Color = 49407
- With .[a2].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = 3 To m + 1
- .Cells(i, n) = Application.Sum(.Cells(i, 2).Resize(, n - 2))
- Next
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|