|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- 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("分数线")
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(2, c)
- For j = 1 To UBound(arr, 2)
- km = Left(arr(1, j), 2)
- d1(km) = arr(2, j)
- Next
- End With
- With Worksheets("成绩表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 3 To UBound(arr, 2) Step 2
- If d1.exists(arr(1, j)) Then
- fs = d1(arr(1, j))
- For i = 2 To UBound(arr)
- If arr(i, j) >= fs Then
- If Not d.exists(arr(1, j)) Then
- Set d(arr(1, j)) = .Range("a1").Resize(1, c)
- End If
- Set d(arr(1, j)) = Union(d(arr(1, j)), .Cells(i, 1).Resize(1, c))
- End If
- Next
- End If
- Next
- End With
- For Each aa In d.keys
- On Error Resume Next
- Set ws = Worksheets(aa)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = aa
- End If
- On Error GoTo 0
- With ws
- .Cells.Clear
- d(aa).Copy .Range("a1")
- End With
- Next
-
- ' With .UsedRange
- ' .HorizontalAlignment = xlCenter
- ' .VerticalAlignment = xlCenter
- ' End With
- ' With Worksheets("sheet1")
- ' r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- ' c = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
- ' End With
- End Sub
复制代码 |
|