|
代码已经调试通过。。。- 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 & "MY DOCUMENT"
- If Not fso.FolderExists(p1) Then fso.CreateFolder p1
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("Sheet4")
- With ws
- ws.Sheets("Sheet5").Visible = -1
- arr = sh.UsedRange
- End With
- For i = 8 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- For Each k In d.keys
- ws.Sheets(Array("Sheet4", "Sheet5")).Copy
- Set wb = ActiveWorkbook
- wb.Sheets("Sheet5").Visible = 0
- m = 0
- ReDim brr(1 To d(k).Count, 1 To UBound(arr, 2))
- With wb.Sheets(sh.Name)
- .Name = k
- .DrawingObjects.Delete
- .UsedRange.Offset(7 + d(k).Count).Clear
- For Each kk In d(k).keys
- fn = k
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(kk, j)
- Next
- Next
- .Range("a:a,g:g").NumberFormatLocal = "@"
- .[a8].Resize(m, UBound(brr, 2)) = brr
- End With
- wb.SaveAs p1 & fn
- wb.Close 1
- Next
- ws.Sheets("Sheet5").Visible = 0
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "拆分完毕,共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|