Formula to return a name a certain number of times

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a date range with names in column A and column G will count how many times this person is signed up for a class between column B to column F. Taking into account how many classes the person is taking, I need to return their names in a list that many times

Data Range
A​
B​
C​
D​
E​
F​
G​
1​
Class 1​
Class 2​
Class 3​
Class 4​
Class 5​
Count​
2​
Jim​
1​
1​
3​
Jane​
1​
1​
1​
3​
4​
Joe​
1​
1​
2​
5​
Jack​
1​
1​
1​
1​
4​

<tbody>
</tbody>

Results
J​
1​
List​
2​
Jim​
3​
Jane​
4​
Jane​
5​
Jane​
6​
Joe​
7​
Joe​
8​
Jack​
9​
Jack​
10​
Jack​
11​
Jack​

<tbody>
</tbody>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This should do it.

Code:
Sub listEm()
Dim AR()
Dim Output()
Dim Cnt As Long


AR = Range("A2:G" & Range("A" & Rows.Count).End(xlUp).Row())
Cnt = 1


For i = 1 To UBound(AR)
    For j = 1 To AR(i, 7)
        ReDim Preserve Output(1 To Cnt)
        Output(Cnt) = AR(i, 1)
        Cnt = Cnt + 1
    Next j
Next i


Range("J1").Resize(UBound(Output), 1).Value = Application.Transpose(Output)


End Sub
 
Upvote 0
Here is another macro (no loops) that you can also consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub ListByCounts()
  Dim LastRow As Long, Arr As Variant
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Arr = Split(Join(Application.Transpose(Evaluate(Replace("IF({1},REPT(A2:A#&"" "",G2:G#))", "#", LastRow))), ""))
  Range("J2").Resize(UBound(Arr) + 1) = Application.Transpose(Arr)
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Here is a link to another way of doing it with helper columns and formulas...
 
Upvote 0
Thanks all for the solutions.

sheetspread,

Yes, a formula solution is exactly what I was after. Thank you for your time.
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,263
Members
449,149
Latest member
mwdbActuary

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