|
- Sub 汇总()
- Dim arr, x&, dk, k%
- Dim sh As Worksheet, xRng As Range
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- For Each sh In Worksheets
- If Not sh.Name Like "*汇总*" Then
- r = sh.[c65536].End(3).Row
- arr = sh.Range("a1:i" & r)
- For x = 1 To UBound(arr)
- If arr(x, 1) Like "*年*" And InStr(arr(x, 1), "成绩单") = 0 Then bj = arr(x, 1) '班级名
- If Len(arr(x, 4)) > 0 And IsNumeric(arr(x, 4)) Then '判断第5列为数值,则累计加1
- xkey = sh.Name & bj '字典key为学校+年班
- d(xkey) = d(xkey) + 1
- End If
- Next
-
- For x = 1 To UBound(arr)
- If arr(x, 1) Like "*年*" And InStr(arr(x, 1), "成绩单") = 0 Then
- bj = arr(x, 1)
- xkey = sh.Name & bj '学校+年班
- n = d(xkey): m = n - Round(n * 0.1 + 0.49999, 0) '班级的总人数,计分人数
- a = x + 2 '分数开始行
- ElseIf Len(arr(x, 4)) > 0 And IsNumeric(arr(x, 4)) Then '判断第5列为数值,则累计总分
- For j = 5 To 9 '各学科分数所在列
- If Len(arr(a - 1, j)) > 0 Then '表示学科非空
- Set xRng = sh.Cells(a, j).Resize(n, 1) '该年班、学科所在的区域
- kk = xkey & Left(arr(a - 1, j), 2)
- fs = Val(arr(x, j))
- If fs > 0 Then If Application.WorksheetFunction.Rank(fs, xRng) < m Then d1(kk) = d1(kk) + fs '前m名算总分
- End If
- Next
- End If
- Next
- End If
- Next
-
- dk = d.keys: dt = d.items
- ReDim crr(1 To d.Count, 1 To 10)
- For Each sh In Worksheets
- If sh.Name Like "*汇总*" Then
- sh.Range("a3:j1000").ClearContents
- n = 0
- For i = 0 To UBound(dk)
- xkey = dk(i)
- If Left(sh.Name, 2) = Mid(xkey, 3, 2) Then
- n = n + 1
- crr(n, 1) = xkey
- crr(n, 2) = Left(xkey, 2)
- crr(n, 3) = Mid(xkey, 3)
- crr(n, 4) = dt(i)
- crr(n, 5) = crr(n, 4) - Round(crr(n, 4) * 0.1 + 0.49999, 0)
- For j = 6 To 10
- kk = xkey & Left(sh.Cells(2, j), 2)
- crr(n, j) = d1(kk)
- Next
- End If
- Next
- sh.[a3].Resize(n, 10) = crr
- End If
- Next
- End Sub
复制代码 |
|