New list with repeated entries

Daniel N

New Member
Joined
Jan 30, 2017
Messages
2
Hello,

What I wish to do is the following:

Based on these two lists:

Entry11
Entry23
Entry30

<tbody>
</tbody>

Create the following list:

Entry1
Entry2
Entry2
Entry2

<tbody>
</tbody>

In words that is: To make a list which repetes the content of column 1 as many times as specified by column 2.

I tried searching and writing such a function on my own but quickly ran into problems.

Can someone assist with an easy solution?

Thanks,
Daniel
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the forum.

If you want a formula solution, try:

ABCD
1ListCountNew List
2Entry11Entry1
3Entry23Entry2
4Entry30Entry2
5Entry42Entry2
6Entry51Entry4
7Entry4
8Entry5
9

<tbody>
</tbody>
Sheet2

Array Formulas
CellFormula
D2{=IFERROR(INDEX($A$2:$A$10,SMALL(IF(ROWS($D$2:$D2)-1< SUBTOTAL(9,OFFSET($B$2,0,0,ROW($B$2:$B$10)-ROW($B$2)+1)),ROW($B$2:$B$10)-ROW($B$2)+1),1)),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>




Put the formula in D2, change the references to match your sheet, confirm with Control+Shift+Enter. Drag it down the column as far as needed.

You could also do this with a VBA routine.

Let us know if this helps.
 
Last edited:
Upvote 0
This solution worked perfectly! Thanks alot for the help!

If it's not too much trouble it would be quite interesting and educational to see the VBA routine as well.

/Daniel
 
Upvote 0
There are a lot of ways to do this with VBA, here's one.

Press Alt-F11 to open the VBA editor, from the menu, click Insert > Module, and paste this into the window that opens:

Rich (BB code):
Sub MakeList()
Dim InData As Variant, OutData() As Variant
Dim InLoc As String, OutLoc As String, LastRow As Long, i As Long, x As Long, TotRows As Long

    InLoc = "A1"
    OutLoc = "D1"
    
    LastRow = Cells(Rows.Count, Left(InLoc, 1)).End(xlUp).Row
    InData = Range(InLoc).Resize(LastRow, 2)
    TotRows = WorksheetFunction.Sum(Range(InLoc).Offset(0, 1).Resize(LastRow, 1))
    ReDim OutData(1 To TotRows + 1, 1 To 1)
    OutData(1, 1) = "New List"
    
    x = 2
    For i = 2 To UBound(InData)
        For j = 1 To InData(i, 2)
            OutData(x, 1) = InData(i, 1)
            x = x + 1
        Next j
    Next i
    
    Columns(Left(OutLoc, 1) & ":" & Left(OutLoc, 1)).ClearContents
    Range(OutLoc & ":" & Left(OutLoc, 1) & TotRows + 1) = OutData
    
End Sub
Change the cells in red to match your sheet. Must be row 1, and headings expected. Press F5 to run the code. Or, go back to Excel, press Alt-F8 and choose MakeList and Run it.

Glad to help!
 
Upvote 0

Forum statistics

Threads
1,216,138
Messages
6,129,099
Members
449,486
Latest member
malcolmlyle

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