|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
-
-
- Sub 汇总()
- Const 标准 = 30 '补贴标准
- Dim d As Object, dd, dt, arr, a(), n, i%, R%, C%, k
- arr = Sheet1.Range("a1").CurrentRegion
- Set d = CreateObject("Scripting.Dictionary")
- Set dd = CreateObject("Scripting.Dictionary")
- Set dt = CreateObject("Scripting.Dictionary")
- For i = 2 To UBound(arr)
- dt(arr(i, 2)) = dt(arr(i, 2)) & "、" & arr(i, 4)
- Next
-
- For i = 0 To dt.Count - 1
- C = Month(dt.keys()(i))
- dd.RemoveAll
- For Each k In Split(Mid(dt.items()(i), 2), "、")
- dd(k) = k
- Next
-
- For Each k In dd.keys
- If Not d.Exists(k) Then
- n = n + 1: d(k) = n
- ReDim Preserve a(1 To 12, 1 To n)
- a(C, n) = 1
- Else
- R = d.Item(k)
- a(C, R) = a(C, R) + 1
- End If
- Next
- Next
- Sheet3.Select
- Application.ScreenUpdating = False
- With Range("A4:p10000")
- .ClearContents
- .Borders.LineStyle = xlNone
- End With
- Range("A4").Resize(d.Count, 1) = WorksheetFunction.Transpose(d.keys)
- Range("B4").Resize(d.Count, 12) = WorksheetFunction.Transpose(a)
- Range("N4").Resize(d.Count, 1).FormulaR1C1 = "=SUM(RC2:RC13)"
- Range("O4").Resize(d.Count, 1).FormulaR1C1 = "=RC14*" & 标准
- With Range("A4").Offset(d.Count, 0)
- .Value = "合计"
- .Offset(0, 1).Resize(1, 14).FormulaR1C1 = "=SUM(R2C:R" & d.Count + 3 & "C)"
- End With
- Range("A3").CurrentRegion.Borders.LineStyle = xlContinuous
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|