Macro to insert replicates in database

  • Thread starter Thread starter JA
  • Start date Start date
J

JA

Name Entry
Wynand Botsh 3
Wynand Botsh 3
Wynand Botsh 3
James K 5
Steve Dowson 8
Kim Philips 10

I want to insert multiples of same name in a database
based on the number in a field called Entry. From the
example above James K has to be inserted 5 times before
Steve Dowson.

Please, write a macro to perform the task. I would be very
grateful.
 
Sub AddNames()
Dim LastRow As Long, i As Long, j As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LastRow To 1 Step -1
If Cells(i, 2).Value > 1 Then
Cells(i + 1, 1).Resize(Cells(i, 2) - 1).EntireRow.Insert
For j = 1 To 2
Cells(i + 1, j).Resize(Cells(i, 2) - 1).Value = Cells(i, j)
Next
End If
Next

End Sub

This assumes there is one entry per name and that the first three entries
you show are what it would look like after the macro was run.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top