|
Option Explicit
Sub test()
Dim ar, i&, dic As Object, vKey, Rng As Range, wks As Worksheet, strFileName$, strPath$
DoApp False
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
ar = .Value
Set Rng = .Rows(1)
For i = 2 To UBound(ar)
If Not dic.exists(ar(i, 10)) Then
Set dic(ar(i, 10)) = Rng
End If
Set dic(ar(i, 10)) = Union(dic(ar(i, 10)), .Rows(i))
Next
End With
strPath = ThisWorkbook.Path & "\"
For Each vKey In dic.keys
strFileName = strPath & vKey
With Workbooks.Add
dic(vKey).Copy
.Sheets(1).[A1].PasteSpecial xlPasteColumnWidths
dic(vKey).Copy .Sheets(1).[A1]
.SaveAs strFileName
.Close
End With
Next
Set dic = Nothing: Set Rng = Nothing
DoApp
Beep
End Sub
Function DoApp(Optional b As Boolean = True)
With Application
.ScreenUpdating = b
.DisplayAlerts = b
.Calculation = -b * 30 - 4135
End With
End Function
|
|