跳到主要内容

如何在Excel中基于一个或多个条件返回多个匹配值?

通常,使用VLOOKUP函数对我们大多数人来说查找特定值并返回匹配项很容易。 但是,您是否曾经尝试过根据一个或多个条件返回多个匹配值,如下面的屏幕快照所示? 在本文中,我将介绍一些用于解决Excel中复杂任务的公式。

根据一个或多个条件使用数组公式返回多个匹配值


根据一个或多个条件使用数组公式返回多个匹配值

例如,我要提取所有年龄为28岁且来自美国的姓名,请使用以下公式:

1。 将以下公式复制或输入到要查找结果的空白单元格中:

=INDEX($B$2:$B$11, SMALL(IF(COUNTIF($F$2, $C$2:$C$11)*COUNTIF($G$2, $D$2:$D$11), ROW($A$2:$D$11)-MIN(ROW($A$2:$D$11))+1), ROW(A1)), COLUMN(A1))

备注:在以上公式中, B2:B11 是从中返回匹配值的列; F2, C2:C11 是第一个条件和包含第一个条件的列数据; G2, D2:D11 是第二个条件,并且包含此条件的列数据,请根据需要进行更改。

2。 然后按 Ctrl + Shift + Enter 键以获取第一个匹配结果,然后选择第一个公式单元格并将填充手柄向下拖动到这些单元格,直到显示错误值,现在,所有匹配值都将返回,如下图所示:

Tips:如果只需要根据一种条件返回所有匹配值,请应用以下数组公式:

=IFERROR(INDEX($B$2:$B$11, SMALL(IF($F$2=$D$2:$D$11, ROW($D$2:$D$11)-ROW($D$2)+1), ROW(1:1))),"" )


更多相关文章:

  • 在一个逗号分隔的单元格中返回多个查找值
  • 在Excel中,我们可以应用VLOOKUP函数从表单元格中返回第一个匹配的值,但是有时,我们需要提取所有匹配的值,然后用特定的分隔符(例如逗号,破折号等)分隔为单个单元格如下图所示。 我们如何在Excel中的一个逗号分隔的单元格中获取并返回多个查找值?
  • Vlookup并在Google表格中一次返回多个匹配值
  • Google表格中的常规Vlookup函数可以帮助您根据给定的数据查找并返回第一个匹配值。 但是,有时,您可能需要vlookup并返回所有匹配的值,如下图所示。 您有什么简便的方法可以解决Google表格中的此任务?
  • Vlookup并从下拉列表中返回多个值
  • 在Excel中,如何从下拉列表中进行vlookup并返回多个相应的值,这意味着当您从下拉列表中选择一项时,其所有相对值会立即显示,如以下屏幕截图所示。 本文,我将逐步介绍解决方案。
  • Vlookup并在Excel中垂直返回多个值
  • 通常,您可以使用Vlookup函数来获取第一个对应的值,但是有时您希望基于特定条件返回所有匹配的记录。 本文,我将讨论如何进行vlookup并将所有匹配值垂直,水平或返回到单个单元格中。
  • Vlookup并在Excel中返回两个值之间的匹配数据
  • 在Excel中,我们可以应用常规的Vlookup函数基于给定的数据获取相应的值。 但是,有时,我们想要vlookup并返回两个值之间的匹配值,如下面的屏幕快照所示,您如何在Excel中处理此任务?

 


  • 超级公式栏 (轻松编辑多行文本和公式); 阅读视图 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 和保存数据; 拆分单元格内容; 合并重复的行和总和/平均值...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 收藏并快速插入公式,范围,图表和图片; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级筛选 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 数据透视表分组依据 周号,周几等 显示未锁定的单元格 用不同的颜色 突出显示具有公式/名称的单元格...
kte选项卡201905
  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部

 

Comments (25)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, if there are duplicate values (e.g. two adams), how do i make sure that it only returns 1 adam and not 2?
This comment was minimized by the moderator on the site
Hello, Bobby,
To extract only unique matching values, you should apply the below formula:
After pasting the formula, please press Ctrl + Shift + Enter keys together to get the correct result.
=IFERROR(INDEX($B$2:$B$5, MATCH(0, COUNTIF(H1:$H$1, $B$2:$B$5)+IF($D$2:$D$5<>$G$2, 1, 0)+IF($C$2:$C$5<>$F$2, 1, 0), 0)), "")

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi,

Thanks for posting these examples.
I'm trying to implement this in my own sheet, but don't get it to work (maybe because I'm using an europe version of excel)?

I want to get the dates of the days that I had my shifts or that I have worked 'some' (>0) hours for a client.

So in I3 is the name and in J3 the month. K3 and L3 are the shifts (1 is worked) and hours (don't know how to set this, should be more than zero)

My expected results are in:
Shifts: I7 and I8
hours: J7

So I worked more than 0 hours for 'person 2' in oktober on 3-10-2022
had shifts for person 2 on '10-10-2022' and 28-10-2022

When I add '=INDEX($B$2:$B$11, SMALL(IF(COUNTIF($F$2, $C$2:$C$11)*COUNTIF($G$2, $D$2:$D$11), ROW($A$2:$D$11)-MIN(ROW($A$2:$D$11))+1), ROW(A1)), COLUMN(A1))' in my excel sheet, it doesn't allow the comma between the different parts of the formula.
So I need to change them to ';'.
But when I try it it always says: '#NAME?'

So can someone help me with this?

Kind regards,

Bas
[img]https://drive.google.com/file/d/1iIPQKuj_PNhqWyWlwJ4IQTqGNEd6B9Hw/view?usp=share_link[/img]
This comment was minimized by the moderator on the site
Hi,

First, thank you for sharing!

Can you please provide a solution to the case below:

I have 3 columns (A: Containing reference information, B: Containing information to be searched, C: Search result)

Image url is provided below

https://ibb.co/VHCd09K

Column A-------------------------Column B------------Column C
File Name-------------------------Name----------------File Name, Document Name, Element Name, Name
Changed Element-----------------Element--------------Changed Element, Element Name, Element ID
Column Location
Document Name
Element Name
Name
Category
Warranty
Slope
Element ID

What I need is to search in column A for any partial match with cell B2 (Name) or B3 (Element) and get the result in one cell,

Thank you, Behzad
This comment was minimized by the moderator on the site
Hello, Behzad
Maybe the below User Defined Function can help you.
Public Function ConcatPartLookUp(rngInput As Range, rngSource As Range, Optional strDelimiter As String, Optional blCaseSensitive)
Dim rng As Range
If strDelimiter = "" Then strDelimiter = ","
If IsMissing(blCaseSensitive) Then
    blCaseSensitive = False
Else
    blCaseSensitive = True
End If
For Each rng In rngSource
    If blCaseSensitive Then
        If InStr(1, rng.Value, rngInput.Value, vbBinaryCompare) > 0 Then ConcatPartLookUp = ConcatPartLookUp & strDelimiter & rng.Value
    Else
        If InStr(1, rng.Value, rngInput.Value, vbTextCompare) > 0 Then ConcatPartLookUp = ConcatPartLookUp & strDelimiter & rng.Value
    End If
Next
If Len(ConcatPartLookUp) > 0 Then ConcatPartLookUp = Mid(ConcatPartLookUp, 2, Len(ConcatPartLookUp))
End Function


After copying and pasting this code, and then use this formula:=ConcatPartLookUp(B2,$A$2:$A$8) to get the result you need.
Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Heyi, thank you for the formula. It worked for "fixed" values / text as criterias. However, one of the criterias i'm trying to use is a condition (values <>0 ), but does not work the described formula. Do you guys know what should i change to adapt the formula so I can have a condition as one of the criterias, please?

Best,

João
This comment was minimized by the moderator on the site
Hello, Marcus
To solve your problem, please view this article:
https://www.extendoffice.com/documents/excel/6393-excel-vlookup-function.html#b3-2
There are some detailed explanations of this task. You just need to change the criteira to your own.
Thank you!
This comment was minimized by the moderator on the site
Hi,

if in cell H1 i write "Name" and wanted to link that with the formula, how would that work?
Then I could write "ID" in cell H1 and would automatically get as a result: AA1004; DD1009; PP1023 (for the first formula)

Thank you in advance!
This comment was minimized by the moderator on the site
Hello, Marie
Sorry, i can't get the point of your first problem, could you explain your problem more clearly and detailedly? Or you can insert a screenshot here to describe your problem.
As for the second question, you just need to change the cell reference as this:
=INDEX($A$2:$A$11, SMALL(IF(COUNTIF($F$2, $C$2:$C$11)*COUNTIF($G$2, $D$2:$D$11), ROW($A$2:$D$11)-MIN(ROW($A$2:$D$11))+1), ROW(A1)), COLUMN(A1))

Remeber to press Ctrl + Shift + Enter keys together.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hello,
what would be needed to expand the first formula in the following case:
Some IDs are Blank (e.g. cell A5 is blank) and I would like an additional condition outputting lines only when the IDs are not blank. (So the output should then be James and Abdul.
Thanks!
This comment was minimized by the moderator on the site
Hello, Jo,
To solve your problem, please apply the below formula:
=INDEX($B$2:$B$11, SMALL(IF(COUNTIF($F$2, $C$2:$C$11)*COUNTIF($G$2, $D$2:$D$11)*($A$2:$A$11<>0), ROW($A$2:$D$11)-MIN(ROW($A$2:$D$11))+1), ROW(A1)), COLUMN(A1))

Please have a ry, hope it can help you!
This comment was minimized by the moderator on the site
hello,
ive tried using the formula and it either generates a value of 0 or the image attached
This comment was minimized by the moderator on the site
Hello, Milku
Your screenshot showed WPS software of MAC version, so I am not sure whether our formula is available.
I uploaded an Excel file to here, you can try to see if it can calculate correctly in you environment.
Thank you!
This comment was minimized by the moderator on the site
When I use the second formula and drag down, nothing appears. The formula result (fx) says it should be returning something but it is blank. How do I correct this?
This comment was minimized by the moderator on the site
Hello Alysia,

Glad to help. I tried the second formula in the article and drag the formula down, the rest of results were returned. I think there may be two reasons for your problem. First, maybe you forget to press Ctrl + Shift + Enter keys to enter the formula. Second, the matching result is only one, so no other results are not returned. Please have a check.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Hi,

I was wondering if it at all possible to enter a 2nd criteria but from the same range as the 1st criteria,

For example with the used example above i would like to search for the names of people from both America and France So cell F3 would have France, Scarlett & Andrew would also populate in the list in Column G

Thank you for assistance in advance.
This comment was minimized by the moderator on the site
Hello Nick,

Glad to help. If you want to get the names of people from both America and France, I advise you to use our formula twice to get the result. Please see the screenshot, In F2 and G2 are values "United States" and "France". Apply formula =IFERROR(INDEX($B$2:$B$11, SMALL(IF($F$2=$D$2:$D$11, ROW($D$2:$D$11)-ROW($D$2)+1), ROW(1:1))),"" ) to get the results for America. And apply formula =IFERROR(INDEX($B$2:$B$11, SMALL(IF($G$2=$D$2:$D$11, ROW($D$2:$D$11)-ROW($D$2)+1), ROW(1:1))),"" ) to get the results for France. It's simple. Please have a try.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
In the first example, what change to the formula would be needed to return everyone who was less than 28 years old?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations