Extract Comma-Separated Matches Based on Multiple Criteria and Order Preservation

sobuj53

New Member
Joined
Jan 16, 2014
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a dataset with four columns (A:D) and a cell (E5) containing comma-separated values. I need to extract all matching values from column B that meet specific criteria while preserving the order presented in cell E5.
ABCD
201-0012
301-0011This
401-0013
101-00102This
101-0045zInfThis
701-0016
701-0014This

Now in Cell E5 I have following value: 1, 3
I'm trying to match each value of E5 with column A, while the corresponding value of column D should contain "This" and Column C should not contain "zInf" and then return all matching value from column B.
The output should look like: 01-00102, 01-0014 , 01-0011. I have following formula,
Excel Formula:
=TEXTJOIN(", "; TRUE; FILTER(B1:B7; (ISNUMBER(MATCH(A1:A7; FILTERXML("<t><s>" & SUBSTITUTE(E5; ", "; "</s><s>") & "</s></t>"; "//s"); 0))) * (D1:D7="This") * (C1:C7<>"zInf")); "")

However this formula sorts the returned value, so I'm getting 01-0011, 01-00102, 01-0014 instead of 01-00102, 01-0014 , 01-0011. I need the retuned value in order they appear in Cell E5.

I have anther formula
Excel Formula:
=TEXTJOIN(", "; TRUE; INDEX(B1:B7; MATCH(FILTERXML("<t><s>" & SUBSTITUTE(E5; ", "; "</s><s>") & "</s></t>"; "//s"); IF((D1:D7="This")*(C1:C7<>"zInf"); A1:A7; ""); 0)))

this formula works but it only returns the first matching value, not all matching value from column B.


I'd really appreciate if someone could help me out in this matter. Thank you.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
I have office 356 subscription.
 
Upvote 0
Hi,
I have a dataset with four columns (A:D) and a cell (E5) containing comma-separated values. I need to extract all matching values from column B that meet specific criteria while preserving the order presented in cell E5.
ABCD
201-0012
301-0011This
401-0013
101-00102This
101-0045zInfThis
701-0016
101-0014This

Now in Cell E5 I have following value: 1, 3
I'm trying to match each value of E5 with column A, while the corresponding value of column D should contain "This" and Column C should not contain "zInf" and then return all matching value from column B.
The output should look like: 01-00102, 01-0014 , 01-0011. I have following formula,
Excel Formula:
=TEXTJOIN(", "; TRUE; FILTER(B1:B7; (ISNUMBER(MATCH(A1:A7; FILTERXML("<t><s>" & SUBSTITUTE(E5; ", "; "</s><s>") & "</s></t>"; "//s"); 0))) * (D1:D7="This") * (C1:C7<>"zInf")); "")

However this formula sorts the returned value, so I'm getting 01-0011, 01-00102, 01-0014 instead of 01-00102, 01-0014 , 01-0011. I need the retuned value in order they appear in Cell E5.

I have anther formula
Excel Formula:
=TEXTJOIN(", "; TRUE; INDEX(B1:B7; MATCH(FILTERXML("<t><s>" & SUBSTITUTE(E5; ", "; "</s><s>") & "</s></t>"; "//s"); IF((D1:D7="This")*(C1:C7<>"zInf"); A1:A7; ""); 0)))

this formula works but it only returns the first matching value, not all matching value from column B.


I'd really appreciate if someone could help me out in this matter. Thank you.
Sorry I mistyped A7 value it should be 1 not 7. Now it is correct.
 
Upvote 0
Thanks for that (y)
How about
Excel Formula:
=LET(s,--TEXTSPLIT(E5,", "),f,FILTER(A1:B7,(ISNUMBER(XMATCH(A1:A7,s)))*(D1:D7="this")*(C1:C7<>"zinf")),TEXTJOIN(", ",,SORTBY(INDEX(f,,2),XMATCH(INDEX(f,,1),s))))
 
Upvote 1
Solution
Perhaps:

Book1
ABCDEFG
1201-001201-0011
2301-0011This01-00102
3401-001301-0014
4101-00102This
5101-0045zInfThis1,3
6701-0016
7101-0014This
Sheet1
Cell Formulas
RangeFormula
G1:G3G1=LET(v,TOCOL(IF(A1:A7=--TEXTSPLIT(E5,",")*(D1:D7="This")*(C1:C7<>"zInf"),B1:B7,""),1),FILTER(v,v<>""))
Dynamic array formulas.
 
Upvote 1
Thanks for that (y)
How about
Excel Formula:
=LET(s,--TEXTSPLIT(E5,", "),f,FILTER(A1:B7,(ISNUMBER(XMATCH(A1:A7,s)))*(D1:D7="this")*(C1:C7<>"zinf")),TEXTJOIN(", ",,SORTBY(INDEX(f,,2),XMATCH(INDEX(f,,1),s))))
Thank you so much. This works perfectly. Many many thanks. 🤝
 
Upvote 0
Perhaps:

Book1
ABCDEFG
1201-001201-0011
2301-0011This01-00102
3401-001301-0014
4101-00102This
5101-0045zInfThis1,3
6701-0016
7101-0014This
Sheet1
Cell Formulas
RangeFormula
G1:G3G1=LET(v,TOCOL(IF(A1:A7=--TEXTSPLIT(E5,",")*(D1:D7="This")*(C1:C7<>"zInf"),B1:B7,""),1),FILTER(v,v<>""))
Dynamic array formulas.
Thank you for your suggestion. This works however it returns a spilled range. However, I need them in a comma separated list.
Excel Formula:
=TEXTJOIN(", ", TRUE, LET(v,TOCOL(IF(A1:A7=--TEXTSPLIT(E5,",")*(D1:D7="This")*(C1:C7<>"zInf"),B1:B7,""),1),FILTER(v,v<>"")))
I modified your formula, and this also works but not retaining the order of match.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
=TEXTJOIN(", ",TRUE,IF(A1:A7=--TEXTSPLIT(E5,",")*(D1:D7="This")*(C1:C7<>"zInf"),B1:B7,""))
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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