excel vlookup 有多个结果
我正在尝试使用 vlookup 或类似的函数来搜索工作表,匹配帐号,然后返回指定的值。我的问题是存在重复的帐号,我希望结果将结果连接成一个字符串。
Acct No CropType
------- ---------
0001 Grain
0001 OilSeed
0001 Hay
0002 Grain
在第一个工作表中,在第二个工作表上,我有包含其他信息的帐号,我需要将所有匹配结果放入第二个工作表上的一列中,即。 “谷物油籽干草”
I am trying to use a vlookup or similar function to search a worksheet, match account numbers, then return a specified value. My problem is there are duplicate account numbers and I would like the result to concatenate the results into one string.
Acct No CropType
------- ---------
0001 Grain
0001 OilSeed
0001 Hay
0002 Grain
Is in the first worksheet, on the 2nd worksheet I have the Acct No with other information and I need to get all the matching results into one column on the 2nd worksheet ie. "Grain Oilseed Hay"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个可以为您完成此操作的函数。它与 Vlookup 略有不同,因为您只给它搜索列,而不是整个范围,然后作为第三个参数,您将告诉它向左(负数)或向右(正数)多少列才能获得你的返回值。
我还添加了使用分隔符的选项,在您的情况下您将使用“”。下面是为您调用的函数,假设帐户编号的第一行是 A,结果是 B 行:
这是函数:
注意:
确保字符串不以额外的分隔符结尾。
显然,如果你输入实际范围,速度会更快。
Here is a function that will do it for you. It's a little different from Vlookup in that you will only give it the search column, not the whole range, then as the third parameter you will tell it how many columns to go left (negative numbers) or right (positive) in order to get your return value.
I also added the option to use a seperator, in your case you will use " ". Here is the function call for you, assuming the first row with Acct No. is A and the results is row B:
Here is the function:
Notes:
make sure the string doesn't end with an extra seperator.
obviously it's faster if you enter the actual range.
一种方法是使用数组公式将所有匹配项填充到隐藏列中,然后将这些值连接到字符串中以进行显示:
数字。
输入数组公式 (Ctrl+Shift+Enter),然后根据需要向下复制。
如果您需要解释公式的任何部分,请告诉我。
One way to do this would be to use an array formula to populate all of the matches into a hidden column and then concatenate those values into your string for display:
numbers.
Enter as an array formula (Ctrl+Shift+Enter) and then copy down as far as necessary.
Let me know if you need any part of the formula explaining.
我刚刚遇到了类似的问题,并且我已经查找了很长时间类似的解决方案,但没有什么真正说服我。要么你必须编写一个宏,要么编写一些特殊的函数,而对于我的需要,最简单的解决方案是使用 Excel 等数据透视表。
如果您根据数据创建一个新的数据透视表,并首先添加“Acct No”作为行标签,然后添加“CropType”作为 RowLabel,您将获得一个非常好的分组,其中列出了每个帐户的所有作物类型。但它不会在单个单元格中做到这一点。
I've just had a similar problem and I have looked up similar solutions for a long time, nothing really convinced me though. Either you had to write a macro, or some special function, while yet, for my needs the easiest solution is to use a pivot table in e.g. Excel.
If you create a new pivot table from your data and first add "Acct No" as row label and then add "CropType" as RowLabel you will have a very nice grouping that lists for each account all the crop types. It won't do that in a single cell though.
这是我的代码,它甚至比 Excel vlookup 更好,因为您可以选择条件列,并且肯定还有分隔符(也可以使用回车符)...
还有一个礼物,您还可以对同一单元格的多个元素进行查找(基于相同的分隔符)。真的很有用,
上一个子需要这个功能
Here is my code which even better than an excel vlookup because you can choose to criterie colum, and for sure a separator (Carriege return too)...
And a gift, you can make also a lookup on multiple element of the same cell (based on the same separator). Really usefull
Previous sub needs this function
像这样使用:
=VLookupAll(K1, A1:C25, 3)
查找范围 A1:A25 中所有出现的 K1 值,并返回 C 列中的相应值,用 分隔逗号。
如果要对值求和,可以使用 SUMIF,例如
=SUMIF(A1:A25, K1, C1:C25)
对 C1:C25 中的值求和,其中 A 列中的相应值等于K1 的值。
一切都最好。
Use like this:
=VLookupAll(K1, A1:C25, 3)
to look up all occurrences of the value of K1 in the range A1:A25 and to return the corresponding values from column C, separated by commas.
If you want to sum values, you can use SUMIF, for example
=SUMIF(A1:A25, K1, C1:C25)
to sum the values in C1:C25 where the corresponding values in column A equal the value of K1.
ALL D BEST.