|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim ws As Worksheet
- Dim wb As Workbook
- Dim mypath$, myname$
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- For Each ws In Worksheets
- With ws
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 1 To UBound(arr, 2)
- If arr(2, j) = "所属销售" Then
- Exit For
- End If
- Next
- Set d1(ws.Name) = .Range("a1").Resize(2, c)
- If j <= UBound(arr, 2) Then
- For i = 3 To UBound(arr)
- If Not d.exists(arr(i, j)) Then
- Set d(arr(i, j)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, j)).exists(ws.Name) Then
- Set d(arr(i, j))(ws.Name) = .Cells(i, 1).Resize(1, c)
- Else
- Set d(arr(i, j))(ws.Name) = Union(d(arr(i, j))(ws.Name), .Cells(i, 1).Resize(1, c))
- End If
- Next
- End If
- End With
- Next
- Application.SheetsInNewWorkbook = d1.Count
- For Each aa In d.keys
- Set wb = Workbooks.Add
- m = 0
- With wb
- For Each bb In d1.keys
- m = m + 1
- With .Worksheets(m)
- .Name = bb
- d1(bb).Copy .Range("a1")
- If d(aa).exists(bb) Then
- d(aa)(bb).Copy .Range("a3")
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- Else
- ' .Cells(3, 3) = CDate("2018-" & Replace(ws.Name, ".", "-"))
- ' .cells(3,4).resize(
- End If
- r = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
- .Cells(r, 6) = "当日合计:"
- .Cells(r, 7) = "=SUM(R3C:R[-1]C)"
- End With
- Next
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa
- .Close False
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|