Return all instances if cell contains name

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
209
Office Version
  1. 365
Platform
  1. Windows
Book2
ABCDE
1PatternsNamesStaffOutput
2Pattern 1Tom, HarryTomPattern 1, Pattern 2
3Pattern 2Jack, Sam, TomHarryPattern 1, Pattern 5
4Pattern 3Sara, JaneSaraPattern 3, Pattern 4, Pattern 5
5Pattern 4Sara JanePattern 3
6Pattern 5Harry, SaraKen
Sheet1


Can I please have a solution tailored for Excel 2016 (no textjoin) for this scenario. Am after a formula/function to return the requested output in column E.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this in E2:

=TEXTJOIN(",",1,IF(ISNUMBER(SEARCH(D2,$B$2:$B$6)),$A$2:$A$6,""))
 
Upvote 0
Until a more elegant solution comes along...
Book1
ABCDE
1PatternsNamesStaffOutput
2Pattern 1Tom, HarryTomPattern 1, Pattern 2
3Pattern 2Jack, Sam, TomHarryPattern 1, Pattern 5
4Pattern 3Sara, JaneSaraPattern 3, Pattern 4, Pattern 5
5Pattern 4Sara JanePattern 3
6Pattern 5Harry, SaraKen 
Sheet1
Cell Formulas
RangeFormula
E2:E6E2=IFERROR(LEFT(CONCAT(IF(ISNUMBER(FIND(D2,$B$2:$B$6)),$A$2:$A$6&", ","")),LEN(CONCAT(IF(ISNUMBER(FIND(D2,$B$2:$B$6)),$A$2:$A$6&", ","")))-2),"")
 
Upvote 0
Am after a formula/function to return the requested output
Can it be a user-defined function using vba?
If not how many rows do you actually have (or could you actually have) in columns A:B in your real data?
 
Upvote 0
Can it be a user-defined function using vba?
If not how many rows do you actually have (or could you actually have) in columns A:B in your real data?
UDF is okay if we can't find an easier formula, Col A around 35 rows, Col B around 5 rows.
 
Upvote 0
:confused: Don't column A and column B have equal number of rows of data?
Did you mean column D instead of column B?
I may have oversimplified this, the actual data in cold A & B have approx 35 rows.
 
Upvote 0
the actual data in cold A & B have approx 35 rows.
In that case a worksheet formula solution for Excel 2016 is not feasible in my view.
You could instead try this user-defined function.

VBA Code:
Function StaffPatterns(rData As Range, sStaff As String) As String
  StaffPatterns = Join(Filter(Split(Join(Filter(Application.Transpose(Evaluate(rData.Columns(1).Address & "&""@|, ""&" _
      & rData.Columns(2).Address & "&"",""")), ", " & sStaff & ","), "@"), "@"), "|", False), ", ")
End Function

tigerzen.xlsm
ABCDE
1PatternsNamesStaffOutput
2Pattern 1Tom, HarryTomPattern 1, Pattern 2
3Pattern 2Jack, Sam, TomHarryPattern 1, Pattern 5
4Pattern 3Sara, JaneSaraPattern 3, Pattern 4, Pattern 5
5Pattern 4SaraJanePattern 3
6Pattern 5Harry, SaraKen 
Sheet1
Cell Formulas
RangeFormula
E2:E6E2=StaffPatterns(A$2:B$6,D2)
 
Upvote 0
Just out of interest, have you tested the formula from post #4 against your 35 rows? All of the functions used are meant to be available in 2016, and I'd be keen to know if they didn't work :unsure:
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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