|
代码调试通过。。。- Sub ykcbf() '//2024.2.3 总表按部门拆分为多表
- Dim wb, arr, sh
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- p1 = p & "各部门信息"
- If Not fso.FolderExists(p1) Then fso.CreateFolder p1
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("出库单")
- On Error Resume Next
- For Each sht In ws.Sheets
- If sht.Name <> sh.Name Then sht.Delete
- Next
- arr = sh.UsedRange
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 21))
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- For Each k In d.keys
- sh.Copy after:=Sheets(Sheets.Count)
- Set sht = Sheets(Sheets.Count)
- m = 0
- ReDim brr(1 To d(k).Count, 1 To UBound(arr, 2))
- With sht
- .Name = k & "部门"
- .DrawingObjects.Delete
- .UsedRange.Offset(1 + d(k).Count).Clear
- For Each kk In d(k).keys
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(kk, j)
- Next
- Next
- .[a2].Resize(m, UBound(brr, 2)) = brr
- End With
- Next
- sh.Activate
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "拆分完毕,共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|