|
Sub t()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim arr, d, k, i As Integer, ts As String
Dim sh As Worksheet
arr = Sheet1.[a1].CurrentRegion
Set d = CreateObject("Scripting.Dictionary")
ts = MsgBox("只保留总表", vbYesNo)
If ts = vbNo Then Exit Sub
For Each sh In Sheets
If sh.Name <> "总表" Then
sh.Delete
End If
Next
For i = 2 To UBound(arr) - 1
d(arr(i, 3)) = ""
Next
k = d.keys
For i = 0 To d.Count - 1
With Sheet1
.Range("a1:l1").AutoFilter Field:=3, Criteria1:=k(i)
Sheets.Add(after:=Sheets(Sheets.Count)).Name = k(i)
.Range("a1:l" & .[a65536].End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy ActiveSheet.[a1]
'.[a1:g2].Copy ActiveSheet.[a1]
End With
Next
Sheet1.Range("c1").AutoFilter
Sheet1.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "拆分OK,共拆分" & d.Count & "张表" & Chr(10) & Chr(10) & Join(k, ";")
Set d = Nothing
End Sub
|
|