|
Sub 计算()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "成绩表为空!": End
.Range("g2:h" & r) = Empty
ar = .Range("a1:q" & r)
For j = 12 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
For i = 2 To UBound(ar)
hj = 0
If Trim(ar(i, 2)) <> "" Then
For j = 3 To 5
lh = d(Trim(ar(i, j)))
If lh <> "" Then
hj = hj + ar(i, lh)
End If
Next j
For j = 9 To 11
hj = hj + ar(i, j)
Next j
ar(i, 7) = hj
zd = Trim(ar(i, 3)) & "|" & Trim(ar(i, 4)) & "|" & Trim(ar(i, 5))
dc(zd) = ""
End If
Next i
.Range("a2:q" & r) = Empty
For Each k In dc.keys
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
zd = Trim(ar(i, 3)) & "|" & Trim(ar(i, 4)) & "|" & Trim(ar(i, 5))
If zd = k Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
Next i
For i = 1 To n
For s = i + 1 To n
If br(i, 7) < br(s, 7) Then
For j = 2 To UBound(ar, 2)
kk = br(i, j)
br(i, j) = br(s, j)
br(s, j) = kk
Next j
End If
Next s
br(i, 1) = i
br(i, 8) = i
Next i
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(rs, 1).Resize(n, UBound(br, 2)) = br
Next k
End With
Set d = Nothing
Set dc = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|