|
- Sub 按班级排序法()
- Dim N
- Dim Rng As Range
- r = [c65536].End(3).Row
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- With Sheet3
- .Activate
- .UsedRange.ClearContents
- Columns("a:L").Copy .[a1]
- For i = 2 To r
- .Cells(i, "M") = i - 1
- Next
- .Range("a2:M" & r).Sort key1:=.Cells(2, 1), order1:=xlAscending, key2:=.Cells(2, 13), order2:=xlAscending '按班级排序
- arr = .[a1].CurrentRegion
- For i = 2 To UBound(arr) '按班级排序后,以班级最末行为item
- d(arr(i, 1)) = i
- Next
- dk = d.keys: dt = d.items
- For j = 4 To 12
- sr = 2 '每个班级首行
- If j <> 7 And j <> 8 Then '物理、化学无数据
- For i = 0 To UBound(dt)
- er = dt(i) '每个班级末行
- Set Rng = .Range("a" & sr & ":M" & er)
- N = er - sr + 1 '班级总人数
- yx = Round(N * 0.3, 0) '按比例优秀人数
- lh = Round(N * 0.4, 0) '按比例良好人数
- hg = N - yx - lh '按比例合格人数
- Rng.Sort key1:=.Cells(2, j), order1:=xlDescending
- .Cells(sr, j).Resize(yx, 1) = "优秀"
- .Cells(sr + yx, j).Resize(lh, 1) = "良好"
- .Cells(sr + yx + lh, j).Resize(hg, 1) = "合格"
- sr = er + 1 '下一班级首行
- Next
- End If
- Next
- .Range("a2:M" & r).Sort key1:=.Cells(2, 1), order1:=xlAscending, key2:=.Cells(2, 13), order2:=xlAscending
- .Range("m:m").Clear
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|