Duplicating rows based on data in column

cuallaidh

New Member
Joined
Jun 6, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. MacOS
I have a spreadsheet that looks like this:

UPCProductQtyPrice
123456789098Product 1109.99
098765432123Product 227.00
456789098765Product 311.99

What I need to do is create a new worksheet that has each row copied the number of times in the Qty column so Product 1 should be copied 10 times, product 2 twice and Product 3 just the once.

I have tried looking at other scripts on here for similar solutions, but cannot seem to get any of them to work right. I am using Exel v16 on Mac OS.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
Sub t()
Dim i As Long
With ActiveSheet
    For i = .Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        Rows(i).Copy
        Rows(i).Offset(1).Resize(.Cells(i, "C").Value).EntireRow.Insert
    Next
End With
End Sub
 

shaowu459

Well-known Member
Joined
Apr 26, 2018
Messages
515
Office Version
  1. 365
Platform
  1. Windows
Creat a helper column in A:A, enter formula in G2, drag to the right and down, until it returns "".
Cell Formulas
RangeFormula
G2:J17G2=IF(ROW(A1)>SUM($D:$D),"",IFERROR(VLOOKUP(ROW(A1),$A:$E,COLUMN(B1),),G3))
A2:A4A2=SUM(D$2:D2)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,281
Messages
5,595,240
Members
413,981
Latest member
nady94

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
Top