|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 统计平均分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long
Dim br(), brr()
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
t = Timer
With Sheets("成绩表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(4, Columns.Count).End(xlToLeft).Column
If r < 2 Or y < 4 Then MsgBox "成绩表为空,请先导入数据!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim brr(1 To UBound(ar), 1 To UBound(ar, 2) - 1)
brr(1, 1) = "序号"
brr(1, 2) = "班级"
For j = 4 To UBound(ar, 2)
brr(1, j - 1) = ar(1, j)
Next j
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = d(ar(i, 1)) + 1
If Not dc.exists(ar(i, 1)) Then Set dc(ar(i, 1)) = CreateObject("scripting.dictionary")
dc(ar(i, 1))(i) = ""
End If
Next i
m = 1
For Each k In dc.keys
m = m + 1
brr(m, 1) = m - 1
brr(m, 2) = k & "班"
sl = d(k)
If sl * 0.3 = Int(sl * 0.3) Then
gs = sl * 0.3
Else
gs = Int(sl * 0.3) + 1
End If
n = 0
ReDim br(1 To dc(k).Count, 1 To UBound(ar, 2))
For Each kk In dc(k).keys
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(kk, j)
Next j
Next kk
For j = 4 To UBound(ar, 2)
zxz = Application.Small(Application.Index(br, 0, j), gs)
zf = 0
For i = 1 To n
If br(i, j) <> "" Then
If IsNumeric(br(i, j)) Then
If br(i, j) <= zxz Then
zf = zf + br(i, j)
End If
End If
End If
Next i
brr(m, j - 1) = Format(zf / gs, "0.00")
Next j
Next k
With Sheets("统计")
.[a1].CurrentRegion.Borders.LineStyle = 0
.[a1].CurrentRegion = Empty
.[a1].Resize(m, UBound(brr, 2)) = brr
.[a1].Resize(m, UBound(brr, 2)).Borders.LineStyle = 1
.Activate
End With
Set d = Nothing
Set dc = Nothing
Application.ScreenUpdating = True
MsgBox "耗时:" & Format(Timer - t, "0.00") & "秒!"
End Sub
|
|