|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("成绩")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- End With
- mc = Application.InputBox(prompt:="请问要取前多少名?", Title:="操作提示", Default:=10, Type:=1)
- If mc > UBound(arr) - 1 Then
- mc = UBound(arr) - 1
- End If
- For j = 3 To UBound(arr, 2)
- fs = Application.Large(Application.Index(arr, 0, j), mc)
- For i = 2 To UBound(arr)
- If arr(i, j) >= fs Then
- If Not d.exists(arr(1, j)) Then
- m = 1
- ReDim brr(1 To 4, 1 To m)
- Else
- brr = d(arr(1, j))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 4, 1 To m)
- End If
- brr(1, m) = arr(i, 1)
- brr(2, m) = arr(i, 2)
- brr(3, m) = arr(i, j)
- d(arr(1, j)) = brr
- End If
- Next
- Next
- For Each aa In d.keys
- brr = d(aa)
- ReDim crr(1 To UBound(brr, 2), 1 To UBound(brr))
- For i = 1 To UBound(brr)
- For j = 1 To UBound(brr, 2)
- crr(j, i) = brr(i, j)
- Next
- Next
- d1.RemoveAll
- For i = 1 To UBound(crr)
- d1(crr(i, 3)) = d1(crr(i, 3)) + 1
- Next
- nn = 1
- kk = d1.keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d1(mm)
- d1(mm) = nn
- nn = nn + ss
- Next
- For i = 1 To UBound(crr)
- crr(i, 4) = d1(crr(i, 3))
- Next
- d(aa) = crr
- Next
- With Worksheets("结果")
- .UsedRange.Offset(1, 0).Clear
- r1 = 2
- For Each aa In d.keys
- brr = d(aa)
- With .Cells(r1, 1)
- .Value = aa
- .Resize(UBound(brr), 1).Merge
- End With
- .Cells(r1, 2).Resize(UBound(brr), UBound(brr, 2)) = brr
- .Cells(r1, 2).Resize(UBound(brr), UBound(brr, 2)).Sort key1:=.Cells(r1, 5), order1:=xlAscending, Header:=xlNo
- With .Cells(r1, 1).Resize(UBound(brr), 1 + UBound(brr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- r1 = r1 + UBound(brr)
- Next
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
-
- With Worksheets("结果1")
- .Cells.Clear
- n = 1
- For Each aa In d.keys
- brr = d(aa)
- With .Cells(1, n)
- .Value = aa
- .Resize(1, 4).Merge
- End With
- .Cells(2, n).Resize(1, 4) = Array("班级", "姓名", "成绩", "排名")
- .Cells(3, n).Resize(UBound(brr), UBound(brr, 2)) = brr
- .Cells(3, n).Resize(UBound(brr), UBound(brr, 2)).Sort key1:=.Cells(3, n + 3), order1:=xlAscending, Header:=xlNo
- With .Cells(1, n).Resize(2 + UBound(brr), UBound(brr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- n = n + 5
- Next
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
评分
-
4
查看全部评分
-
|