zhaojiaoyang200 发表于 2014-1-22 20:33
我问过老师了,"缺考"按0处理.这道题我也想出了解决的办法,但太复杂了.
这个是个半成品,后面可以把表2作为辅助工作表,输出过程结果、排序、读入内存数组却掉最后5名再输入。这样一个循环下来即可。- Sub 成绩分析()
- Dim ar, re, temp
- Dim d As Object, i As Integer, j As Integer, R As Integer, Cnt As Integer
- Set d = CreateObject("Scripting.Dictionary")
- ar = Sheets(1).Range("A3").CurrentRegion
- ReDim re(1 To 999, 1 To 10)
- ReDim temp(1 To 999, 1 To 11)
- For i = 3 To 12
- re(1, i - 2) = ar(3, i)
- Next
- Cnt = 1
- For i = 4 To UBound(ar)
- If Not d.exists(ar(i, 3)) Then
- Cnt = Cnt + 1
- d(ar(i, 3)) = Cnt
- re(Cnt, 1) = ar(i, 3)
- temp(Cnt, 11) = 1
- For j = 4 To 12
- If Not (ar(i, j) = "缺考" Or ar(i, j) = " ") Then temp(Cnt, j - 2) = ar(i, j)
- Next j
- Else
- R = d(ar(i, 3))
- temp(R, 11) = temp(R, 11) + 1
- For j = 4 To 12
- If Not (ar(i, j) = "缺考" Or ar(i, j) = " ") Then temp(R, j - 2) = temp(Cnt, j - 2) + ar(i, j)
- Next
- End If
- Next
- For i = 2 To Cnt
- For j = 2 To 10
- re(i, j) = temp(i, j) / temp(i, 11)
- Next
- Next
- Sheets(2).[a1].Resize(Cnt, 10) = re
- End Sub
复制代码 |