|
Option Explicit
Sub test()
Dim ar, i&, dic As Object, vKey, Rng As Range, strFileName$, strPath$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set dic = CreateObject("Scripting.Dictionary")
ar = [A1].CurrentRegion
Set Rng = Range("A2:A3").Resize(, UBound(ar, 2))
For i = 4 To UBound(ar)
If Not dic.exists(ar(i, 3)) Then
Set dic(ar(i, 3)) = Rng
End If
Set dic(ar(i, 3)) = Union(dic(ar(i, 3)), Cells(i, 1).Resize(, UBound(ar, 2)))
Next
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
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|