简体   繁体   English

"Excel:在一个单元格中查找多个值并在另一个单元格中返回结果"

[英]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.

相关问题 Excel2011-在日期之前查找并将多个值返回到一个单元格 - Excel2011 - Lookup and return multiple values into one cell BY DATE 查找 MULTIPLE 值并在满足至少一个条件时返回特定单元格 - Lookup for MULTIPLE values and return a specific cell if AT LEAST ONE criteria is met Excel - 在字符串中查找多个值并返回第一个 - Excel - lookup multiple values in a string and return first one Excel 可以返回多个结果的查找索引 - Excel lookup index that can return multiple results 使用excel VBA查找单元格值,并基于该单元格返回多个值 - Using excel VBA to lookup cell value, and return multiple values based on that cell Excel VBA中的自定义函数,该函数在返回多个匹配值并将其组合到一个单元格的范围内查找单元格值 - Custom function in excel vba that lookup a cell value in a range that returns multiple match values and combine them in one cell 如何从逗号分隔的单元格中查找多个值并在excel中平均结果? - How do I lookup multiple values from a comma separated cell and average the results in excel? 如何在Excel中的一个单元格中查找多个值? - How To Vlookup To Return Multiple Values In One Cell In Excel? 查找并将唯一的多个值连接到一个单元格中 - Lookup and concatenate unique multiple values into one cell VBA 以逗号分隔返回多个查找值的代码有效,但如果有空单元格则崩溃 - VBA code to return multiple lookup values in one comma separated works but crashes if there's an empty cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM