|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim d As Object
- Dim d1 As Object
- Dim r%, i%
- Dim arr, brr
- Dim ws As Worksheet
- Dim rng As Range
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("全部")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:g" & r)
- Set rng = .Cells(1, 1).Resize(1, 7)
- For i = 2 To UBound(arr)
- If Not d.Exists(arr(i, 3)) Then
- Set d(arr(i, 3)) = .Cells(i, 1).Resize(1, 7)
- Else
- Set d(arr(i, 3)) = Union(d(arr(i, 3)), .Cells(i, 1).Resize(1, 7))
- End If
- Next
- End With
- For Each ws In Worksheets
- d1(ws.Name) = ""
- Next
- For Each aa In d.Keys
- If Not d1.Exists(aa) Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- With ws
- .Name = aa
- rng.Copy .Range("a1")
- End With
- End If
- With Worksheets(aa)
- If .Cells(1, 1) <> "准考证号" Then
- .Cells.Clear
- rng.Copy .Range("a1")
- End If
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- d(aa).Copy .Range("a" & r + 1)
- End With
- Next
- End Sub
复制代码 |
|