|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下:
- Sub ykcbf() '//2023.1.10
- Application.ScreenUpdating = False
- Dim arr, brr, d, r
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Dim tm: tm = Timer
- nf = Sheet2.[a1]
- On Error Resume Next
- With Sheet1
- r = .Cells(Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:n" & r)
- End With
- For i = 2 To UBound(arr)
- yf = Month(arr(i, 3)) & "月份"
- s = arr(i, 12) & "|" & yf
- If Year(arr(i, 3)) = nf Then
- If arr(i, 1) <> Empty Then
- d1(yf) = d1(yf) + 1
- If arr(i, 12) <> Empty Then
- d(s) = d(s) + 1
- End If
- End If
- End If
- Next
- t = d.items
- ReDim brr(1 To UBound(arr), 1 To 13)
- For Each k In d.keys
- m = m + 1
- brr(m, 1) = Split(k, "|")(0)
- Next
- With Sheet2
- .UsedRange.Offset(3).Clear
- .[a4].Resize(m, 1) = brr
- arr = .Range("a3").Resize(1000, 13)
- For i = 2 To UBound(arr)
- For j = 2 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(1, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- .Range("a3").Resize(1000, 13) = arr
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- .Cells(r + 1, 1) = "统计"
- .Cells(r + 1, 2).Resize(1, 12).FormulaR1C1 = "=SUM(R4C:R" & "[-1]C)" '//全部合计
- .Cells(r + 2, 1) = "月份总笔数"
- For j = 2 To 13
- .Cells(r + 2, j) = d1(arr(1, j))
- Next
- .Cells(r + 3, 1) = "不良率"
- For j = 2 To 13
- .Cells(r + 3, j) = Format(.Cells(r + 1, j) / .Cells(r + 2, j), "0.00%")
- Next
- .[a4].Resize(r, 13).Borders.LineStyle = 1
- End With
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "运行完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|