将excel按照某一列拆分成多个文件(方案整理)

1解决方案:将excel按照某一列拆分成多个文件

百度得:https://blog.csdn.net/ntotl/article/details/79141314

2遇到问题:解决vbe6ext.olb不能被加载 内存溢出 问题

百度得:http://www.udaxia.com/wtjd/13635.html

3问题原因:VBA文件位置不同

有的是:C:\Program Files (x86)\Common Files\microsoft shared\VBA

有的是:C:\Program Files \Common Files\microsoft shared\VBA

而我两个位置都有VBA文件。所以我先把两个地方的VBA文件复制一份(怕搞错无法恢复),然后把两个地方的VBA6、VBA7.1 都试了一篇,最后成功了。

4VB核心代码:

Sub 保留表头拆分数据为若干新工作簿()
Dim arr, d As Object, k, t, i&, lc%, rng As Range, c%
c = Application.InputBox("请输入拆分列号", , , , , , , )
If c = Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
arr = [a1].CurrentRegion
lc = UBound(arr, )
Set rng = [a1].Resize(, lc)
Set d = CreateObject("scripting.dictionary")
For i = To UBound(arr)
If Not d.Exists(arr(i, c)) Then
Set d(arr(i, c)) = Cells(i, ).Resize(, lc)
Else
Set d(arr(i, c)) = Union(d(arr(i, c)), Cells(i, ).Resize(, lc))
End If
Next
k = d.Keys
t = d.Items
For i = To d.Count -
With Workbooks.Add(xlWBATWorksheet)
rng.Copy .Sheets().[a1]
t(i).Copy .Sheets().[a2]
.SaveAs Filename:=ThisWorkbook.Path & "\" & k(i) & ".xls"
.Close
End With
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "完毕"
End Sub
上一篇:数据结构与算法JavaScript (三) 链表


下一篇:MSSQL优化之——查看语句执行情况