|
- Sub 拆分()
- Dim arr
- Dim ws As Worksheet
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("出库单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:u" & r)
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 21)) Then
- Set d(arr(i, 21)) = .Cells(1, 1).Resize(1, 21)
- Else
- Set d(arr(i, 21)) = Union(d(arr(i, 21)), .Cells(i, 1).Resize(1, 21))
- End If
- Next
- End With
- For Each aa In d.keys
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- With ws
- d(aa).Copy .Range("a1")
- .Name = aa & "部门"
- End With
- Next
- Worksheets("出库单").Activate
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- End Sub
复制代码 |
|