- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("成绩")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:i" & r)
- End With
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- For j = 4 To 6
- If Not d(arr(i, 1)).exists(arr(1, j)) Then
- ReDim brr(1 To 20)
- brr(1) = arr(1, j)
- Else
- brr = d(arr(i, 1))(arr(1, j))
- End If
- brr(2) = brr(2) + 1
- If Len(arr(i, j)) <> 0 Then
- brr(3) = brr(3) + 1
- brr(5) = brr(5) + arr(i, j)
- If arr(i, j) >= 80 Then
- brr(7) = brr(7) + 1
- End If
- If arr(i, j) >= 60 Then
- brr(9) = brr(9) + 1
- End If
- If IsEmpty(brr(11)) Then
- brr(11) = arr(i, j)
- Else
- If brr(11) < arr(i, j) Then
- brr(11) = arr(i, j)
- End If
- End If
- If IsEmpty(brr(12)) Then
- brr(12) = arr(i, j)
- Else
- If brr(12) > arr(i, j) Then
- brr(12) = arr(i, j)
- End If
- End If
- n = Application.Match(arr(i, j), Array(0, 40, 50, 60, 70, 80, 90, 100))
- If Not IsError(n) Then
- brr(21 - n) = brr(21 - n) + 1
- End If
- d(arr(i, 1))(arr(1, j)) = brr
- End If
- Next
- Next
- With Worksheets("统计")
- .Cells.Clear
- m = 1
- For Each aa In d.keys
- With .Cells(m, 1)
- .Value = aa & "班成绩统计表"
- .Resize(1, 20).Merge
- With .Font
- .Size = 18
- .Bold = True
- End With
- End With
- m = m + 1
- m0 = m
- .Cells(m, 1).Resize(1, 20) = [{"科目","应考人数","参考人数","参考率(%)","总分","平均分","优秀人数","优秀率(%)","及格人数","及格率(%)","最高分","最低分",100,"90-99.5","80-89.5","70-79.5","60-69.5","50-59.5","40-49.5","39.5以下"}]
- For Each bb In d(aa).keys
- m = m + 1
- brr = d(aa)(bb)
- If Len(brr(2)) <> 0 And brr(2) <> 0 Then
- brr(4) = Round(brr(3) / brr(2), 4)
- End If
- If Len(brr(3)) <> 0 And brr(3) <> 0 Then
- brr(6) = Round(brr(5) / brr(3), 2)
- brr(8) = Round(brr(7) / brr(3), 4)
- brr(10) = Round(brr(9) / brr(3), 4)
- End If
- .Cells(m, 1).Resize(1, UBound(brr)) = brr
- Next
- .Cells(m0, 1).Resize(m - m0 + 1, 20).Borders.LineStyle = xlContinuous
- m = m + 2
- Next
- .Range("d:d,h:h,j:j").NumberFormatLocal = "0.00%"
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
-
- End With
- End Sub
复制代码 |