|
发表于 2017-11-2 21:09
|
显示全部楼层
本楼为最佳答案
确实太慢了。居然全部复制了再删除。。。。。
- Sub grf()
- Set d = CreateObject("scripting.dictionary")
- Dim bt As Range, sh As Worksheet
- Application.ScreenUpdating = False
- With Sheets(1)
- arr = .Range("B1:B" & .[b65536].End(3).Row)
- Set bt = .Range("a1:f1") '表头
- For i = 2 To UBound(arr)
- x = arr(i, 1)
- If x <> "" Then
- If Not d.exists(x) Then
- Set d(x) = Union(bt, .Cells(i, 1).Resize(1, 6))
- Else
- Set d(x) = Union(d(x), .Cells(i, 1).Resize(1, 6))
- End If
- End If
- Next
- End With
-
- Call 删除
- For Each x In d.keys
- Application.StatusBar = x
- Sheets.Add after:=Sheets(Sheets.Count)
- ActiveSheet.Name = x
- d(x).Copy ActiveSheet.[a1]
- Next
- Sheets(1).Select
- Application.ScreenUpdating = True
- Application.StatusBar = False
- End Sub
- Sub 删除()
- Application.DisplayAlerts = False
- For Each sh In Worksheets
- If sh.Index > 1 Then sh.Delete
- Next
- Application.DisplayAlerts = True
- End Sub
复制代码 |
|