|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原格式拆分工作表
- Sub ykcbf() '//2024.12.19
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- col = 1 '//拆分列号
- p = ThisWorkbook.Path & ""
- r = Cells(Rows.Count, col).End(3).Row
- c = ActiveSheet.UsedRange.Columns.Count
- arr = [a1].Resize(r, c)
- Set Rng = [a1].Resize(1, c)
- Set d = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- s = CStr(arr(i, col))
- If Not d.Exists(s) Then
- Set d(s) = Union(Rng, Cells(i, 1).Resize(1, c))
- Else
- Set d(s) = Union(d(s), Cells(i, 1).Resize(1, c))
- End If
- Next
- For Each k In d.keys
- With Workbooks.Add
- Set sht = .Sheets(1)
- With .Sheets(1)
- d(k).Copy .[a1]
- .Name = k
- .DrawingObjects.Delete
- End With
- .SaveAs p & k
- .Close
- End With
- Next
- Set Rng = Nothing
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "拆分完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码
|
|