|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim ws As Worksheet
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- sm = Application.SheetsInNewWorkbook
- For Each ws In Worksheets
- With ws
- Set rng = Nothing
- Set rng = .UsedRange.Find(what:="理财中心", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext)
- If Not rng Is Nothing Then
- r0 = rng.Row
- c0 = rng.Column
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- c = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
- If r > r0 Then
- arr = .Cells(1, c0).Resize(r, 1)
- For i = r0 + 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1)).exists(ws.Name) Then
- Set d(arr(i, 1))(ws.Name) = .Range("a1").Resize(r0, c)
- End If
- Set d(arr(i, 1))(ws.Name) = Union(d(arr(i, 1))(ws.Name), .Cells(i, 1).Resize(1, c))
- Next
- End If
- End If
- End With
- Next
- For Each aa In d.keys
- Application.SheetsInNewWorkbook = d(aa).Count
- Set wb = Workbooks.Add
- m = 0
- With wb
- For Each bb In d(aa).keys
- m = m + 1
- With .Worksheets(m)
- .Name = bb
- d(aa)(bb).Copy .Range("a1")
- End With
- Next
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa & ".xls"
- .Close False
- End With
- Next
- Application.SheetsInNewWorkbook = sm
- End Sub
复制代码 |
评分
-
5
查看全部评分
-
|