Hey Excel Gurus,
I have found online a really good piece of vba code but unfortunelaty I can not update it myself as I am a new to VBA.
The below code duplicate record based on a constant in cell d (ie qty 5) and add an incremental number to the new duplicated records
The issue is that when the output of the macro reaches around 15000 lines it stops working.
Any help on making sure that the macro wont stop and will deliver the desire result even if the total of new records is >than 15k???
Thanks in advance
Initial data
[TABLE="width: 407"]
<tbody>[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]qty5[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]qty6[/TD]
[/TR]
</tbody><colgroup><col><col span="3"></colgroup>[/TABLE]
After Macro
[TABLE="width: 407"]
<tbody>[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]001[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]002[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]003[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]004[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]005[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]001[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]002[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]003[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]004[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]005[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]006[/TD]
[/TR]
</tbody><colgroup><col><col span="2"><col></colgroup>[/TABLE]
Public Sub ExpandRecords()
Dim i As Long, _
j As Long, _
LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Columns("D:D").NumberFormat = "@"
For i = LR To 1 Step -1
If CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)) > 1 Then
With Range("A" & i)
.Offset(1, 0).Resize(CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)) - 1, 1).EntireRow.Insert Shift:=xlDown
.Resize(CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)), 1).EntireRow.Value = Range("A" & i).EntireRow.Value
For j = 1 To CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3))
Range("D" & i).Offset(j - 1, 0).Value = Application.Text(j, "000")
Next j
End With
Else
Range("D" & i).Value = Application.Text(1, "000")
End If
Next i
Application.ScreenUpdating = True
End Sub
I have found online a really good piece of vba code but unfortunelaty I can not update it myself as I am a new to VBA.
The below code duplicate record based on a constant in cell d (ie qty 5) and add an incremental number to the new duplicated records
The issue is that when the output of the macro reaches around 15000 lines it stops working.
Any help on making sure that the macro wont stop and will deliver the desire result even if the total of new records is >than 15k???
Thanks in advance
Initial data
[TABLE="width: 407"]
<tbody>[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]qty5[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]qty6[/TD]
[/TR]
</tbody><colgroup><col><col span="3"></colgroup>[/TABLE]
After Macro
[TABLE="width: 407"]
<tbody>[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]001[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]002[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]003[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]004[/TD]
[/TR]
[TR]
[TD]D990304101[/TD]
[TD]US[/TD]
[TD]chicago[/TD]
[TD]005[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]001[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]002[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]003[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]004[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]005[/TD]
[/TR]
[TR]
[TD]D990304109[/TD]
[TD]EU[/TD]
[TD]Paris[/TD]
[TD]006[/TD]
[/TR]
</tbody><colgroup><col><col span="2"><col></colgroup>[/TABLE]
Public Sub ExpandRecords()
Dim i As Long, _
j As Long, _
LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Columns("D:D").NumberFormat = "@"
For i = LR To 1 Step -1
If CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)) > 1 Then
With Range("A" & i)
.Offset(1, 0).Resize(CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)) - 1, 1).EntireRow.Insert Shift:=xlDown
.Resize(CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3)), 1).EntireRow.Value = Range("A" & i).EntireRow.Value
For j = 1 To CLng(Right(Range("D" & i).Value, Len(Range("D" & i).Value) - 3))
Range("D" & i).Offset(j - 1, 0).Value = Application.Text(j, "000")
Next j
End With
Else
Range("D" & i).Value = Application.Text(1, "000")
End If
Next i
Application.ScreenUpdating = True
End Sub