Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "成绩表为空!": End
ar = .Range("a1:h" & r)
End With
rr = Array(10, 9, 8, 7, 6)
With Sheets("统计")
.[a1].CurrentRegion.Borders.LineStyle = 0
.[a1].CurrentRegion = Empty
For j = 6 To 7
k = 1: d.RemoveAll
ReDim br(1 To UBound(ar), 1 To 9)
br(1, 1) = "班级"
br(1, 2) = "人数"
br(1, 8) = "6以下"
br(1, 9) = "满分率"
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
t = d(ar(i, 3))
If t = "" Then
k = k + 1
d(ar(i, 3)) = k
t = k
br(k, 1) = ar(i, 3)
End If
If Trim(ar(i, j)) <> "" Then
If IsNumeric(ar(i, j)) Then
br(t, 2) = br(t, 2) + 1
For s = 0 To UBound(rr)
zf = rr(s)
br(1, s + 3) = zf & "分"
If ar(i, j) = zf Then
br(t, s + 3) = br(t, s + 3) + 1
End If
Next s
If ar(i, j) < 6 Then
br(t, 8) = br(t, 8) + 1
End If
If br(t, 2) = "" Or br(t, 2) = 0 Then
br(t, 9) = 0
Else
br(t, 9) = br(t, 3) / br(t, 2)
End If
End If
End If
End If
Next i
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
If rs = 2 Then
rs = 1
Else
rs = rs
End If
.Cells(rs, 1) = ar(1, j - 2) & "成绩统计表"
.Cells(rs + 1, 1).Resize(k, UBound(br, 2)) = br
.Cells(rs + 1, 1).Resize(k, UBound(br, 2)).Borders.LineStyle = 1
Next j
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|