如何快速的将excel表格数据拆分成多个文件?
时间:2023-07-29 02:22:40
如何将一个EXCEL文件里面很多条数据拆分成多个文件,比如一个EXCEL表里面有90万行数据,需要按照每1万行拆分成一个文件,也就是需要将这表里面的90万行数据拆分到90个文件里面。这个如果手工拆分,那工作量实在太大了。于是,我就想把这个过程拿出来分享一下。实际上这也是大数据处理过程中会涉及到的一个问题——数据分框。
下面我们就来看看如何用VBA来实现拆分工作。
第一,在EXCEL里面插入一个模块,代码如下:
Sub copybat()
Dim n As Integer
Dim i As Integer
Dim k As Integer
Dim path As String
Dim filename As String
path = "c:拆分测试" '预定义的存储路径
filename = "分割文件" '预定义的文件名
Application.ScreenUpdating = False
i = 10 '分页数据条目数
k = 0 '循环执行次数,用于标识文件顺序
For n = 1 To Cells(1, 1).End(xlDown).Row Step i '开始循环到数据表底部,步长为分页条目数
Range("A1:D1,A" & n + 1 & ":D" & n + i).Select '每次均选择复制固定的表头和本次循环内的数据行
Selection.Copy
Workbooks.Add '新建工作簿
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False '特殊粘贴:只粘贴数值
k = k + 1
ActiveWorkbook.SaveAs filename:=path & filename & k & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False '将文件按命名规则另存至指定位置
ActiveWindow.Close '关闭已经生成的文件
Next n
MsgBox "分割完毕!", vbDefaultButton1, "提示"
Application.ScreenUpdating = true
End Sub
第二,在EXCEL工作表里面插入一个按钮,用于调用执行该以上模块。
第三,点击按钮执行代码。最后结果如下:
文件夹下生成的文件图例
分割的第1小部分
分割的第2小部分
以上,是一个大体的过程,实际上还可以在此基础上实现更加复杂的逻辑,这就又各位独立发挥了。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win10系统无法退出家庭组的解决方法
Win10专业版重装系统后没有声音怎么办?
![](https://img.aspxhome.com/file/2023/26/a224259_0s.jpg)
Win10 20H1快速预览18885版怎么升级?
![](https://img.aspxhome.com/file/2023/28/a241319_0s.jpg )
excel2010:创建新空白表格的方法
![](https://img.aspxhome.com/file/2023/6/a143476_0s.jpg)
win7系统局域网无法访问怎么办?
![](https://img.aspxhome.com/file/2023/4/a312039_0s.jpg)
电脑防火墙打不开的解决方法 防火墙打开教程
![](https://img.aspxhome.com/file/2023/27/a231156_0s.jpg)
Win10一周年更新14393.222安装失败怎么办?微软正在开发补丁
![](https://img.aspxhome.com/file/2023/28/a243418_0s.jpg)
Win10电脑开机蓝屏要怎么解决?
![](https://img.aspxhome.com/file/2023/25/a219151_0s.png)
Win11笔记本连接热点(无线)后即自动断网怎么办?
![](https://img.aspxhome.com/file/2023/1/a272734_0s.png)
Win11怎么设置右键单击显示所有选项?
![](https://img.aspxhome.com/file/2023/1/a274899_0s.jpg)
win7开机自动拨号上网上的设置步骤
如何在wps设置表格属性
如何为PPT幻灯片中添加表格
![](https://img.aspxhome.com/file/2023/10/a352285_0s.jpg)
电脑出现开机动画后一直黑屏怎么办?
![](https://img.aspxhome.com/file/2023/6/a322883_0s.jpg)
Win10更换网络后连不上网络打印机的解决教程
![](https://img.aspxhome.com/file/2023/1/a278569_0s.jpg)
epic登录黑屏怎么办-epic登录黑屏解决方法
![](https://img.aspxhome.com/file/2023/3/a292126_0s.jpg)
罗技ghub卡在安装界面上怎么办?罗技ghub卡在安装界面上的解决方法
![](https://img.aspxhome.com/file/2023/6/a321205_0s.jpg)
在Word2007中"标记格式不一致错误"的使用方法
![](https://img.aspxhome.com/file/2023/5/21325_0s.jpg)
如何用PPT做倒计时
![](https://img.aspxhome.com/file/2023/10/a351401_0s.jpg)