|
Sub test()
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Name <> "总表" Then
sh.Delete
End If
Next sh
Set sh = Sheets("总表")
arr = sh.UsedRange
sh.Select
For j = 2 To UBound(arr)
If Len(arr(j, 7)) > 0 Then
If d.exists(arr(j, 7)) Then
Set d(arr(j, 7)) = Union(Cells(j, 1), d(arr(j, 7)))
Else
Set d(arr(j, 7)) = Union(Cells(j, 1), [a1])
End If
End If
Next j
For Each k In d.keys
sh.Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).UsedRange.Clear
Sheets(Sheets.Count).Name = k
d(k).EntireRow.Copy Sheets(Sheets.Count).[a1]
Sheets(Sheets.Count).Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & k & ".xlsx"
ActiveWorkbook.Close True
Next k
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
|
|