排重汇总。。。- Sub ykcbf() '//2024.8.12 排重汇总
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- a = [{"不分月","再定","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}]
- 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
- 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)
- n = 1
- For x = 1 To UBound(a)
- If s = a(x) Then
- n = n + x
- brr(1, n) = s
- Exit For
- End If
- Next
- brr(r, n) = brr(r, n) + 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
复制代码
|