excel - 将 excel 文件分成 5000 行的较小文件,每个文件不拆分行
问题描述
我需要将 60000+ 行的 excel 表分成不同的文件,每个文件大约 5000 行。插入的数据是分组的,我需要新表不要拆分这些组,但我无法做到这一点,也无法每次都创建一个新文件。
我尝试使用以下代码,但无法使其正常运行:
Public Sub split()
Dim sheetnumber, t As Double
line = 0
k = lastrow 'this gives the last full row in the file
sheetnumber = WorksheetFunction.RoundUp(k / 5000, 1)
For i = 1 To sheetnumber Step 1
line = line + 5000
article = CStr(Sheets("sheet1").Cells(linea, 1).Value)
For m = 0 To 30 Step 1
If article = CStr(Sheets("sheet1").Cells(linea + m, 1).Value) Then
GoTo e
Else
line = line + m
Exit For
End If
e:
Next m
Sheets.Add After:=ActiveSheet
For n = 1 To line Step 1
ActiveSheet.Row(n) = Sheets("sheet1").Row(n) ' i also tried to put a cycle here to
'copy the whole row and then go to the next one but the rest won't work
Next n
ActiveSheet.Select
ActiveSheet.Move
Next i
End Sub
该文件的组成如下:
- 第 0 条
- 第1条
- 第1条
- 第1条
- 第 2 条
- 第 2 条
- 第 3 条
...
- 第 56 条
- 第 57 条
- 第 57 条
- 第 57 条
- 第 57 条
- 第五十八条
我需要新文件包含从 5002 到 1 的所有行,另一个文件包含从 10003 到 5002 的所有行,依此类推到文件末尾(最后一行约为 60000),而不会破坏文章组。
感谢您提供任何建议/帮助
解决方案
推荐阅读
- connexion - 我在休息 api 调用上遇到问题-属性只读
- arrays - Ruby 的组合比较运算符是如何工作的?
- apache-spark - Synapase 笔记本中的 Pyspark 数据帧错误
- reactjs - 来自 Django 服务器的 reactjs 请求时出错(403 错误/CORS)
- python-3.x - 从第一个循环中获取结果以在 python 中运行第二个循环
- python - 过滤 dtype 转换失败的行
- php - 做imagecropauto后如何保持gif背景透明度
- python - 数据处理股票?
- python - 我如何检查经过身份验证的用户并显示然后在 django 中显示不同的内容
- html - 如何使一行的边框底部比其他的更大?