本文主要是介绍【Excel VBA】批量拆分工作表为独立文件/独立工作簿(亲测有效),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实用VBA工具,一步步摆脱工具人
把我给的代码,复制到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
这篇关于【Excel VBA】批量拆分工作表为独立文件/独立工作簿(亲测有效)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!