先去重处理,再统计
- Sub ykcbf() '//2024.11.10
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("数据")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 5)
- End With
- ReDim zrr(1 To r, 1 To 5)
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 2))
- d1(s) = d1(s) + 1
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- For j = 1 To UBound(arr, 2)
- zrr(m, j) = arr(i, j)
- Next
- End If
- Next
- d.RemoveAll
- m = 0
- ReDim brr(1 To r, 1 To 8)
- For i = 1 To UBound(zrr)
- s = zrr(i, 1)
- If s <> Empty Then
- p1 = IIf(zrr(i, 4) = "男", 1, 0)
- p2 = IIf(zrr(i, 4) = "女", 1, 0)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m
- brr(m, 2) = s
- brr(m, 3) = p1
- brr(m, 4) = p2
- brr(m, 5) = brr(m, 3) + brr(m, 4)
- Else
- r = d(s)
- brr(r, 3) = brr(r, 3) + p1
- brr(r, 4) = brr(r, 4) + p2
- brr(r, 5) = brr(r, 5) + 1
- End If
- brr(m, 6) = Format(brr(m, 3) / d1.Count, "0.00%")
- brr(m, 7) = Format(brr(m, 4) / d1.Count, "0.00%")
- brr(m, 8) = Format(brr(m, 5) / d1.Count, "0.00%")
- End If
- Next
- With Sheets("汇总")
- .[a4:h10000] = ""
- .[a4].Resize(m, 8) = brr
- .[a4].Resize(m, 8).Borders.LineStyle = 1
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|