Forum

Duplicates based on...
 
Notifications
Clear all

Duplicates based on count

3 Posts
2 Users
0 Reactions
58 Views
(@marsil)
Posts: 72
Estimable Member
Topic starter
 

Hi,

Please can you help to Duplicate the rows based on count.

Example: 

Input:

Industry Duplication Count
Semiconductors 2
Computer Hardware 3

Output:

Industry Number
Semiconductors 1
Semiconductors 2
Computer Hardware 1
Computer Hardware 2
Computer Hardware 3

Please check attached file to get more sample.

 

Thanks;

Marsil

 
Posted : 30/12/2020 8:10 pm
(@purfleet)
Posts: 412
Reputable Member
 

Try this, outputs the detail to column M & N

 

Sub RepeatDown()

Dim R As Range
Dim C As Range
Dim Product As String
Dim NextRow As Integer
Dim ProductQty As Integer

Dim i As Integer

Set R = Range("A2:a7")

For Each C In R

NextRow = Cells(Rows.Count, 13).End(xlUp).Row

Product = C.Value
ProductQty = C.Offset(0, 1).Value

For i = 1 To ProductQty
With Range("m" & NextRow + i)
.Value = Product
.Offset(0, 1).Value = i
End With
Next i

Next C

End Sub

 
Posted : 31/12/2020 5:01 pm
(@marsil)
Posts: 72
Estimable Member
Topic starter
 

Deep thanks Purfleet,

 

Thanks;

Marsil

 
Posted : 01/01/2021 5:23 am
Share: