|
按月份统计- Sub ykcbf2() '//2024.6.28 按月份统计
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("数据库")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 20)
- End With
- ReDim brr(1 To UBound(arr), 1 To 100)
- m = 1: n = 1
- brr(1, 1) = "月度"
- With Sheets("按月度统计")
- For i = 2 To UBound(arr)
- If Val(arr(i, 1)) = .[b2] And Val(arr(i, 3)) = .[b3] Then
- s = arr(i, 2)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = s
- End If
- r = d(arr(i, 2))
- For j = 5 To UBound(arr, 2)
- s = arr(1, j)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = s
- End If
- c = d(arr(1, j))
- brr(r, c) = brr(r, c) + arr(i, j)
- Next
- End If
- Next
- .UsedRange.Offset(1, 3).Clear
- .[e1].Resize(, 26).Clear
- .[d1].Resize(1, n).Interior.Color = 49407
- With .[d1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|