我需要将具有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
文件的组成如下:
...
我需要新文件包含从5002到1的整个行,另一个文件包含从10003到5002的所有行,依此类推直到文件的末尾(最后一行大约是60000),而不会破坏文章组。
感谢您提出任何建议/帮助