Looking for an excel macro ( or some similar thing) . I have a excel file with 100 k rows ( first row is header) . I want to create new sheets ( or new excel files) each not exceeding around 30 k automatically splitting the 100K rows . So there will be 4 sheets created
It desirable the header is copied to each of the sheets ( Not essential)
Note: It could be 90 K rows or it could be 120 k rows or 137234 rows . But splitting in 30 k is need not be kept as a variable
Sub Produce_sheeets()
Dim RID As Integer, Item0 As String
RID = 2
RID1 = 2
RID2 = 1
Count0 = 0
Do While True
Item0 = Trim(Worksheets("S0").Cells(RID, 5).Value)
If Item0 = "" Then
Count0 = Count0 + 1
Else
Count0 = 0
End If
If Count0 = 5 Then
Exit Sub
End If
If Item0 <> "" Then
If Count0 > 30000 Then
Sheets.Add After:=Sheets("S0")
'Append/copy cells's info to new sheet
'..
End If
RID = RID + 1
Loop
End Sub
Dim i As Long, l As Long
With ActiveSheet.UsedRange
l = (.Rows.Count + 4) / 4
For i = 3 To 0 Step -1
Sheets.Add
.Cells.Offset(i * l).Resize(l, .Columns.Count).Copy
ActiveSheet.Paste
Next
End With
End Sub
Open in new window