Formula to return a name a certain number of times

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
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
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A​
[/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[TD]
E​
[/TD]
[TD]
F​
[/TD]
[TD]
G​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD][/TD]
[TD]
Class 1​
[/TD]
[TD]
Class 2​
[/TD]
[TD]
Class 3​
[/TD]
[TD]
Class 4​
[/TD]
[TD]
Class 5​
[/TD]
[TD]
Count​
[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD]
Jim​
[/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
1​
[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]
Jane​
[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD]
3​
[/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]
Joe​
[/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD][/TD]
[TD]
2​
[/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]
Jack​
[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD]
1​
[/TD]
[TD]
1​
[/TD]
[TD]
4​
[/TD]
[/TR]
</tbody>[/TABLE]

Results
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
J​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD]
List​
[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD]
Jim​
[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]
Jane​
[/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]
Jane​
[/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]
Jane​
[/TD]
[/TR]
[TR]
[TD]
6​
[/TD]
[TD]
Joe​
[/TD]
[/TR]
[TR]
[TD]
7​
[/TD]
[TD]
Joe​
[/TD]
[/TR]
[TR]
[TD]
8​
[/TD]
[TD]
Jack​
[/TD]
[/TR]
[TR]
[TD]
9​
[/TD]
[TD]
Jack​
[/TD]
[/TR]
[TR]
[TD]
10​
[/TD]
[TD]
Jack​
[/TD]
[/TR]
[TR]
[TD]
11​
[/TD]
[TD]
Jack​
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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