|
排名代码。
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- Set d3 = 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
- ReDim brr(1 To UBound(arr), 1 To (UBound(arr, 2) - 5) * 3)
- For j = 6 To UBound(arr, 2)
- n = j * 3 - 17
- brr(1, n) = arr(1, j) & "年名"
- brr(1, n + 1) = arr(1, j) & "文理名"
- brr(1, n + 2) = arr(1, j) & "班名"
- d1.RemoveAll
- d2.RemoveAll
- d3.RemoveAll
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- d1(arr(i, j)) = d1(arr(i, j)) + 1
- If Not d2.exists(arr(i, 5)) Then
- Set d2(arr(i, 5)) = CreateObject("scripting.dictionary")
- End If
- d2(arr(i, 5))(arr(i, j)) = d2(arr(i, 5))(arr(i, j)) + 1
- If Not d3.exists(arr(i, 2)) Then
- Set d3(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- d3(arr(i, 2))(arr(i, j)) = d3(arr(i, 2))(arr(i, j)) + 1
- End If
- 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 Each aa In d2.keys
- nn = 1
- kk = d2(aa).keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d2(aa)(mm)
- d2(aa)(mm) = nn
- nn = nn + ss
- Next
- Next
- For Each aa In d3.keys
- nn = 1
- kk = d3(aa).keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d3(aa)(mm)
- d3(aa)(mm) = nn
- nn = nn + ss
- Next
- Next
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- brr(i, n) = d1(arr(i, j))
- brr(i, n + 1) = d2(arr(i, 5))(arr(i, j))
- brr(i, n + 2) = d3(arr(i, 2))(arr(i, j))
- End If
- Next
- Next
- With Worksheets("排名")
- .Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- .Cells(1, UBound(arr, 2) + 1).Resize(UBound(brr), UBound(brr, 2)) = brr
- With .Range("a1").Resize(UBound(arr), UBound(arr, 2) + UBound(brr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- .Columns(1).Resize(, UBound(arr, 2) + UBound(brr, 2)).AutoFit
-
- End With
- Application.ScreenUpdating = True
-
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|