|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 新test()
t = Timer
Dim 成绩 As Integer
Set d = CreateObject("scripting.dictionary")
With Sheets("成绩表2")
.[a1].CurrentRegion.Offset(1, 7).ClearContents
ar = .[a1].CurrentRegion.Resize(, 11)
'==========总分
For i = 2 To UBound(ar)
ar(i, 8) = ar(i, 5) + ar(i, 6) + ar(i, 7)
If Not d.exists(ar(i, 1) & ar(i, 2) & ar(i, 3)) Then '同校同年级同班[即班内]
Set d(ar(i, 1) & ar(i, 2) & ar(i, 3)) = CreateObject("scripting.dictionary")
End If
If Not d.exists(ar(i, 1) & ar(i, 2)) Then '同校同年级[即同校同级]
Set d(ar(i, 1) & ar(i, 2)) = CreateObject("scripting.dictionary")
End If
If Not d.exists(ar(i, 2)) Then '不分学校[不同校同级]
Set d(ar(i, 2)) = CreateObject("scripting.dictionary")
End If
d(ar(i, 2))(ar(i, 8)) = ""
d(ar(i, 1) & ar(i, 2) & ar(i, 3))(ar(i, 8)) = ""
d(ar(i, 1) & ar(i, 2))(ar(i, 8)) = ""
Next i
For i = 2 To UBound(ar)
成绩 = ar(i, 8)
ar(i, 9) = 排名(成绩, d(ar(i, 1) & ar(i, 2) & ar(i, 3)).keys)
ar(i, 10) = 排名(成绩, d(ar(i, 1) & ar(i, 2)).keys)
ar(i, 11) = 排名(成绩, d(ar(i, 2)).keys)
Next i
.[a1].Resize(UBound(ar), UBound(ar, 2)) = ar
End With
MsgBox "运行完毕,共计耗时:" & Format(Timer - t, "0.0000") & "秒"
End Sub
Function 排名(N1 As Integer, N2 As Variant)
For Each nn In N2
If nn >= N1 Then pm = pm + 1
Next
排名 = pm
End Function
|
|