把我给的代码,复制到VBA里面,直接运行,就ok
亲测有效。
有问题请留言~
Sub 保留表头拆分数据为若干新工作簿()
Dim arr, d As Object, k, t, i&, lc%, rng As Range, c%c = Application.InputBox("请输入拆分列号", , 1, , , , , 1)If c = 0 Then Exit SubApplication.ScreenUpdating = FalseApplication.DisplayAlerts = Falsearr = [a1].CurrentRegionlc = UBound(arr, 2)Set rng = [a1].Resize(, lc)Set d = CreateObject("scripting.dictionary")For i = 2 To UBound(arr)If Not d.Exists(arr(i, c)) ThenSet d(arr(i, c)) = Cells(i, 1).Resize(1, lc)ElseSet d(arr(i, c)) = Union(d(arr(i, c)), Cells(i, 1).Resize(1, lc))End IfNextk = d.Keyst = d.ItemsFor i = 0 To d.Count - 1With Workbooks.Add(xlWBATWorksheet)rng.Copy .Sheets(1).[a1]t(i).Copy .Sheets(1).[a2].SaveAs Filename:=ThisWorkbook.Path & "" & k(i) & ".xlsx".CloseEnd WithNextApplication.DisplayAlerts = TrueApplication.ScreenUpdating = TrueMsgBox "完毕"
End Sub
本文发布于:2024-02-01 07:01:14,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170674207234734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |