简体   繁体   中英

How can I search for an item within a cell that's also in a range?

I have Table A :

╔═══╦═════╦═════════════╦══════════════════╗
║   ║  a  ║      b      ║         c        ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 1 ║ ID  ║ LIST VALUES ║ Table B Values   ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 2 ║ 123 ║ 231,583     ║ eggs,bacon       ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 3 ║ 789 ║ 518,732     ║ bacon,bread      ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 4 ║ 101 ║ 55,38       ║ tomato,onion     ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 5 ║ 213 ║ 894,231     ║ ham,eggs         ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 6 ║ 141 ║ 55,38,894   ║ tomato,onion,ham ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 7 ║ 516 ║ 548,43      ║ milk,butter      ║
╚═══╩═════╩═════════════╩══════════════════╝

And I have Table B :

╔═══╦═════╦═════════════╗
║   ║  a  ║      b      ║
╠═══╬═════╬═════════════╣
║ 1 ║ ID  ║ LIST VALUES ║
╠═══╬═════╬═════════════╣
║ 2 ║ 231 ║ eggs        ║
╠═══╬═════╬═════════════╣
║ 3 ║ 518 ║ bacon       ║
╠═══╬═════╬═════════════╣
║ 4 ║ 732 ║ bread       ║
╠═══╬═════╬═════════════╣
║ 5 ║ 55  ║ tomato      ║
╠═══╬═════╬═════════════╣
║ 6 ║ 38  ║ onion       ║
╠═══╬═════╬═════════════╣
║ 7 ║ 894 ║ ham         ║
╠═══╬═════╬═════════════╣
║ 8 ║ 548 ║ milk        ║
╠═══╬═════╬═════════════╣
║ 9 ║ 43  ║ butter      ║
╚═══╩═════╩═════════════╝

These are representations of the data I have, and what I need help with. The actual data is a lot longer than these tables, and the delimited items can be very long.

What I'm trying to do is populate Table A , Column C . I need to search the items from TABLE B , Column A for the listed items in TABLE A , Column B within the cell through the whole range.

I guess this can be done vice versa as well. I am familiar with INDEX-MATCH function, but I'm not sure how to add searching within the cell.

Use TEXTJOIN and ISNUMBER/SEARCH :

=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(","&$G$2:$G$9&",",","&B2&",")),$H$2:$H$9,""))

在此处输入图像描述

If you have Windows Excel, try:

C2: =TEXTJOIN(",",TRUE,VLOOKUP(FILTERXML("<t><s>"&SUBSTITUTE(B2,",","</s><s>")&"</s></t>","//s"),$G$2:$H$9,2,FALSE))

Table A

在此处输入图像描述

Table B

在此处输入图像描述

Results

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM