Dupplicate row X times (X = value in cell)

Beachson

Active Member
Joined
Oct 28, 2009
Messages
468
I have a spreadsheet with up to 50,000 rows. Data spans from A1:BP50000

Each row has a value in column "E"

I would like each row to be duplicated X times ---> X = value in column "E"

If one row has a value of 5 in column "E", duplicate that row 5 times

If another row has a value of 2 in column "E", duplicate that row 2 times

If a row has a value of 0, do not duplicate OR do nothing

Can this be done through VBA?

Thanks for the help
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
Sub addrows()
   Dim i As Long
   
   Application.ScreenUpdating = False
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Range("E" & i) > 1 Then
         Rows(i).Copy
         Rows(i).Resize(Range("E" & i).Value).Insert
      End If
   Next i
End Sub
With 50,000 rows of data, this will be slow.
 
Upvote 0
How about
Code:
Sub addrows()
   Dim i As Long
   
   Application.ScreenUpdating = False
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Range("E" & i) > 1 Then
         Rows(i).Copy
         Rows(i).Resize(Range("E" & i).Value).Insert
      End If
   Next i
End Sub
With 50,000 rows of data, this will be slow.


Fluff, thank you. That did the trick. It took roughly 3 minutes to turn 30,000 rows into 100,000 rows on my machine. Which is a high end PC.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top