Help with an algorithm: Add contents of cell to end of list n times where n is given by another cell

T

TR

Hello, Excel Gurus.

Imagine a list of names in column A. In colum B is a list of integers
(call this "n"). I would like a new list of names containing the names
in column A, each repeated n times, where n varies from name to name.

Any suggestions within Excel? If not, I'll start thinking about other
tools.
 
J

JE McGimpsey

TR said:
Hello, Excel Gurus.

Imagine a list of names in column A. In colum B is a list of integers
(call this "n"). I would like a new list of names containing the names
in column A, each repeated n times, where n varies from name to name.

Any suggestions within Excel? If not, I'll start thinking about other
tools.

This can be easily done using a macro - do you consider that "within
Excel"?

Public Sub RepeatNames()
Dim rCell As Range
Dim rDest As Range
Set rDest = Range("D1")
For Each rCell In Range("B1:B" & _
Range("B" & Rows.Count).End(xlUp).Row)
With rCell
rDest.Resize(.Value) = .Offset(0, -1).Value
Set rDest = rDest.Offset(.Value)
End With
Next rCell
End Sub
 

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

Top