|
本帖最后由 ykcbf1100 于 2024-2-21 14:33 编辑
代码更新一下。- Sub ykcbf() '//2024.2.21
- Dim arr, d
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- With Sheets("数据源")
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- arr = .[a1].Resize(r, 12)
- End With
- b = [{7,10,12}]
- For i = 2 To UBound(arr)
- s = arr(i, 4)
- For j = 8 To 9
- s1 = s & "|" & arr(1, j)
- If Not d1.exists(s1) Then
- d1(s1) = Array(arr(i, j), arr(i, j), arr(i, j), 1)
- Else
- t = d1(s1)
- t(0) = t(0) + arr(i, j)
- t(1) = IIf(t(1) < arr(i, j), arr(i, j), t(1))
- t(2) = IIf(t(2) > arr(i, j), arr(i, j), t(2))
- t(3) = t(3) + 1
- d1(s1) = t
- End If
- Next
- s2 = arr(i, 4) & "|" & arr(i, 11)
- d2(s2) = d2(s2) + 1
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- For j = 1 To UBound(b)
- ss = arr(i, b(j))
- d(s)(ss) = d(s)(ss) + 1
- Next
- Next
- ReDim zrr(1 To d.Count, 1 To 2)
- For Each k In d.keys
- m = m + 1
- zrr(m, 1) = k
- zrr(m, 2) = Val(Replace(k, "单位", ""))
- Next
- On Error Resume Next
- With Sheets("统计结果")
- .UsedRange.Offset(1).Clear
- .[a2].Resize(m, 2) = zrr
- .[a2].Resize(m, 2).Sort .[b2], 1
- arr = .UsedRange
- For i = 2 To UBound(arr)
- If arr(i, 1) <> Empty Then
- For j = 2 To 6
- s = arr(i, 1)
- If d.exists(s) Then
- arr(i, j) = d(s)(arr(1, j))
- End If
- Next
- For j = 7 To 10
- s = arr(i, 1)
- ss = Replace(Replace(arr(1, j), "评价类型-", ""), "个数", "")
- If d.exists(s) Then
- arr(i, j) = d(s)(ss)
- End If
- Next
- For j = 19 To 23
- s = arr(i, 1)
- ss = Replace(Replace(arr(1, j), "数字范围", ""), "个数", "")
- If d.exists(s) Then
- arr(i, j) = d(s)(ss)
- End If
- Next
- t = d1(arr(i, 1) & "|" & "时差")
- arr(i, 11) = Format(t(0) / t(3), "0.00")
- arr(i, 12) = Format(t(1), "0.00")
- arr(i, 13) = Format(t(2), "0.00")
- arr(i, 24) = t(3)
- t = d1(arr(i, 1) & "|" & "文本字数")
- arr(i, 14) = Format(t(0) / t(3), "0.00")
- arr(i, 15) = Format(t(1), "0.00")
- arr(i, 16) = Format(t(2), "0.00")
- arr(i, 17) = d2(arr(i, 1) & "|" & "达标")
- arr(i, 18) = d2(arr(i, 1) & "|" & "不达标")
- End If
- Next
- .UsedRange = arr
- .UsedRange.Borders.LineStyle = 1
- r = .Cells(Rows.Count, 1).End(3).Row
- .Cells(r + 1, 1) = "总计"
- .Cells(r + 1, 2).Resize(1, 23).FormulaR1C1 = "=SUM(R2C:R" & "[-1]C)"
- .UsedRange.Offset(r + 1).Clear
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|