|
- 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")
- sx = [{"班级","考号","姓名","性别","语文","数学","英语","总分"}]
- For k = 1 To UBound(sx)
- d1(sx(k)) = k
- Next
- With Worksheets("全体名单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- .Cells.Clear
- For j = 1 To UBound(arr, 2)
- If d1.exists(arr(1, j)) Then
- n = d1(arr(1, j))
- .Cells(1, n).Resize(UBound(arr), 1) = Application.Index(arr, 0, j)
- End If
- Next
- .Range("a1").Resize(r, c).Sort key1:=.Range("b2"), order1:=xlAscending, Header:=xlYes
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = .Range("a1:h1")
- End If
- Set d(arr(i, 1)) = Union(d(arr(i, 1)), .Cells(i, 1).Resize(1, 8))
- Next
- End With
- brr = d.keys
- For i = 0 To UBound(brr) - 1
- p = i
- For j = i + 1 To UBound(brr)
- If Val(brr(p)) > Val(brr(j)) Then
- p = j
- End If
- Next
- If p <> i Then
- temp = brr(i)
- brr(i) = brr(p)
- brr(p) = temp
- End If
- Next
- For k = 0 To UBound(brr)
- wjm = CStr(brr(k))
- On Error Resume Next
- Set ws = Worksheets(wjm)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = wjm
- End If
- On Error GoTo 0
- With Worksheets(wjm)
- .Cells.Clear
- d(brr(k)).Copy .Range("a1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a1").Resize(r, c).Borders.LineStyle = xlContinuous
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Next
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|