I have a workbook with one column of 30,000+ rows. I'd like to split that column up every 1,000 rows and put it into a new csv workbook with a header. I'd also like to name the new files in numeral order (ex: first 1000 rows go into a new workbook named "1", next 1000 rows go into a workbook named "2", etc)
Currently using a VBA code to split the column into new xlsx workbooks with no header. This code does not save the new workbooks that are created. I'll attach the code if it's easier to just modify it
VBA CODE:
Currently using a VBA code to split the column into new xlsx workbooks with no header. This code does not save the new workbooks that are created. I'll attach the code if it's easier to just modify it
VBA CODE:
VBA Code:
Sub split()
'Set dimensions
Dim Table As Range, TableArray(), _
CutValue As Integer, Cntr As Integer, _
TempArray(), Width As Integer, _
x As Integer, y As Integer, _
Height As Long, Rep As Integer, _
LoopReps As Long
'Get data
Set Table = Application.InputBox("Specify range to copy", _
Default:=ActiveCell.CurrentRegion.Address, Type:=8)
CutValue = InputBox("How many rows should the chunks be?", _
Default:=1000)
Width = 1
Height = Table.Rows.Count
'Write to array
TableArray = Table
ReDim TempArray(1 To CutValue, 1 To Width)
Rep = Application.WorksheetFunction.RoundUp(Height / CutValue, 0)
LoopReps = CLng(CutValue)
'Loop through all new sheets
For Cntr = 0 To Rep - 1
If Height - Cntr * CLng(CutValue) < CLng(CutValue) Then _
LoopReps = Height - Cntr * CLng(CutValue)
For x = 1 To Width
For y = 1 To LoopReps
TempArray(y, x) = TableArray(y + Cntr * CLng(CutValue), x)
Next y
Next x
Workbooks.Add
Range("A1").Resize(LoopReps, Width) = TempArray
Next Cntr
End Sub
Last edited by a moderator: