|
- Sub 将一个工作簿拆分成多个工作簿()
- Dim arr, rng As Range, Sht As Worksheet, dic As Object
- Dim k, t, i As Long, lc As Long, str As String
- Application.ScreenUpdating = False
- arr = Range("a1").CurrentRegion.Value
- lc = UBound(arr, 2)
- Set rng = Rows("1:6")
- Set dic = CreateObject("scripting.dictionary")
- For i = 7 To UBound(arr) - 5
- str = arr(i, 1)
- If Not dic.exists(str) Then
- Set dic(str) = Cells(i, 1).Resize(, lc)
- Else
- Set dic(str) = Union(dic(str), Cells(i, 1).Resize(, lc))
- End If
- Next
-
- k = dic.keys
- t = dic.items
- For i = 0 To dic.Count - 1
- With Workbooks.Add
- With .Sheets(1).[a1]
- ThisWorkbook.Sheets("数据").Rows("1:6").Copy
- .PasteSpecial Paste:=xlPasteAll, Operation:=xlNone
- t(i).Copy .Offset(6, 0)
- End With
- .SaveAs ThisWorkbook.Path & "" & k(i), xlWorkbookDefault '保存工作簿
- .Close True
- End With
- Next
- End Sub
复制代码 |
|