|
本帖最后由 zxsea_7426 于 2023-3-24 08:36 编辑
凑热闹也参与,采用多级字典
- Sub 统计发送()
- Dim arr, brr, ar, i&, j&, s$, d As Object, r, ws&
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- f = Dir(ThisWorkbook.Path & "\参数\需要提取的对象表.xls*.")
- If f = "" Then MsgBox "找不到参数文件!": End
- Set wb = Workbooks.Open(ThisWorkbook.Path & "\参数" & f, 0)
- With wb.Worksheets("明细")
- ar = .Range("a2:n" & .Cells(Rows.Count, 1).End(3).Row)
- End With
- wb.Close False
- Set f = Nothing
- For i = 2 To UBound(ar)
- 年度 = Format(ar(i, 1), "yyyy年")
- If Not d.exists(年度) Then Set d(年度) = CreateObject("Scripting.Dictionary") '一级年度字典
- If ar(i, 14) <> "" Then
- mc_sender = ar(i, 4) & "###" & ar(i, 14)
- If Not d(年度).exists(mc_sender) Then Set d(年度)(mc_sender) = CreateObject("Scripting.Dictionary") '二级名称+发送人字典
- 月份 = Format(ar(i, 1), "m月")
- d(年度)(mc_sender)(月份) = d(年度)(mc_sender)(月份) + ar(i, 10)
- End If
- Next
- With Sheets("发送")
- .[f2] = "2023年"
- .[h2] = "度 月 份 发 送 表"
- ws = .Cells(Rows.Count, 1).End(xlUp).Row
- If ws >= 5 Then .Range("A5:o" & ws).clearcontents
- For Each Key In d.keys
- If Key = "2023年" Then
- .[a5].resize(d("2023年").Count, 1) = Application.Transpose(d("2023年").keys)
- br = .[a4].resize(d("2023年").Count + 1, 15)
- ReDim brr(1 To d("2023年").Count, 1 To 15)
- For i = 2 To UBound(br)
- brr(i - 1, 1) = Split(br(i, 1), "###")(0)
- brr(i - 1, 2) = Split(br(i, 1), "###")(1)
- For j = 3 To UBound(br, 2) - 1
- If d("2023年")(br(i, 1)).exists(br(1, j)) Then
- brr(i - 1, j) = d("2023年")(br(i, 1))(br(1, j))
- brr(i - 1, UBound(brr, 2)) = brr(i - 1, UBound(brr, 2)) + d("2023年")(br(i, 1))(br(1, j))
- End If
- Next
- Next
- With .[a5].resize(UBound(brr), UBound(brr, 2))
- .Value = brr
- .Font.Name = "微软雅黑"
- .Font.Size = 11
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- End With
- End If
- Next Key
- End With
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码
|
|