[英]Excel: Lookup multiple values in one cell and return results in another
I'm trying to find a way to lookup each of several comma separated values in one cell, and return the results as a comma separated list in another cell.我试图找到一种方法来查找一个单元格中的几个逗号分隔值中的每一个,并将结果作为逗号分隔列表返回到另一个单元格中。
The number of values to lookup is not constant, it may be only one, or several hundred.要查找的值的数量不是恒定的,它可能只有一个,也可能是几百个。
Example - Sheet A has the initial values and will hold the returned values.示例 - 工作表 A 具有初始值并将保存返回值。 Sheet B is the table with the data to lookup.
工作表 B 是包含要查找的数据的表。
I've been searching for an answer to this myself and was rather dismayed to find your question - exactly the question I have - without an answer.我自己一直在寻找这个问题的答案,但很沮丧地发现你的问题——正是我的问题——没有答案。
Almost 4 years late, this answer does require Office 365 Excel, and it's not the most elegant, but here's what I've been able to come up with.将近 4 年了,这个答案确实需要 Office 365 Excel,而且它不是最优雅的,但这是我能想到的。
Pick an unused column on your Sheet B (with enough contiguous unused columns to its right to handle spillover of however many values you'll need to be splitting, or use a new sheet dedicated to this) and put this formula into the 2nd row's cell for that column, dragging it down through each cell that has corresponding data back on Sheet A (and assuming your column header "File #s" is column B):
=TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(SheetA!$B2,delim,"<\/y><y>")&"<\/y><\/x>","\/\/y"))<\/code>
在工作表 B 上选择一个未使用的列(在其右侧有足够多的连续未使用列来处理溢出,无论您需要拆分多少值,或使用专门用于此的新工作表)并将此公式放入第二行的单元格对于该列,将其向下拖动到工作表 A 上具有相应数据的每个单元格(并假设您的列标题“文件 #s”是 B 列):
=TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(SheetA!$B2,delim,"<\/y><y>")&"<\/y><\/x>","\/\/y"))<\/code>
Replace
delim<\/code> with your delimiter wrapped in quotes, or a cell reference to a cell that has your delimiter in it.
将
delim<\/code>为用引号括起来的定界符,或对包含定界符的单元格的单元格引用。
Also, if it's possible to have no value in the corresponding cell in Sheet A, then you'll need to wrap the
FILTERXML()<\/code> function (or the whole thing) with
IFERROR()<\/code> .
此外,如果工作表 A 中的相应单元格中可能没有值,那么您需要使用
IFERROR()<\/code>包装
FILTERXML()<\/code>函数(或整个函数)。
Then, back on Sheet A in your Results column, use this formula:
=TEXTJOIN(delim,TRUE,FILTER(SheetB!$B$2:$B$6,COUNTIF(SheetB!D2#,SheetB!$A$2:$A$6),if_no_match))<\/code>
然后,返回结果列中的工作表 A,使用以下公式:
=TEXTJOIN(delim,TRUE,FILTER(SheetB!$B$2:$B$6,COUNTIF(SheetB!D2#,SheetB!$A$2:$A$6),if_no_match))<\/code>
Again, replace
delim<\/code> with the delimiter or cell reference with your delimiter of choice.
同样,将
delim<\/code>为分隔符或单元格引用替换为您选择的分隔符。
SheetB!$B$2:$B$6<\/code> and
SheetB!$A$2:$A$6<\/code> are your lookup table's columns (and thus extend them to encompass the whole thing).
SheetB!$B$2:$B$6<\/code>和
SheetB!$A$2:$A$6<\/code>是查找表的列(因此将它们扩展为包含整个内容)。
The
SheetB!D2#<\/code> references the column where you put the
TRANSPOSE(FILTERXML())<\/code> formula.
SheetB!D2#<\/code>引用了放置
TRANSPOSE(FILTERXML())<\/code>公式的列。
Finally, replace
if_no_match<\/code> with whatever you want to appear if there was no match.
最后,如果没有匹配项,请将
if_no_match<\/code>替换为您想要出现的任何内容。
I'd ideally like to find a way that uses a single, self-contained formula, but alas, this is as far as I've managed so far.理想情况下,我希望找到一种使用单一、自包含公式的方法,但是,到目前为止,这是我所能做到的。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.