|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = True
- Application.DisplayAlerts = False
- With Worksheets("汇")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:l" & r)
- For i = 4 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- Set d(arr(i, 1))(2) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1)).exists(1) Then
- Set d(arr(i, 1))(1) = .Range("a1:l3")
- End If
- Set d(arr(i, 1))(1) = Union(d(arr(i, 1))(1), .Cells(i, 1).Resize(1, 12))
- d(arr(i, 1))(2)(arr(i, 5)) = ""
- Next
- End With
- For Each aa In d.keys
- Application.SheetsInNewWorkbook = 1
- Set wb = Workbooks.Add
- With wb
- With .Worksheets(1)
- .Name = "汇"
- d(aa)(1).Copy .Range("a1")
- End With
- On Error Resume Next
- ThisWorkbook.Worksheets(d(aa)(2).keys).Copy after:=.Worksheets(Worksheets.Count)
- On Error GoTo 0
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa, FileFormat:=xlExcel8
- .Close False
- End With
- Next
-
- End Sub
复制代码 |
|