提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何根据Excel中的条件提取唯一值?

假设您有以下数据范围,您只想根据列A的特定标准仅列出列B的唯一名称,以获得如下所示的结果。 您如何快速轻松地在Excel中处理此任务?

根据数组公式提取唯一值

根据标准Kutools for Excel提取唯一值

doc用标准1提取唯一标识符



为了解决这个问题,你可以应用一个复杂的数组公式,请按如下操作:

1。 输入这个公式: = INDEX($ B $ 2:$ B $ 17,MATCH(0,IF($ D $ 2 = $ A $ 2:$ A $ 17,COUNTIF($ E $ 1:$ E1,$ B $ 2:$ B $ 17),“”),0)) 放到一个空白单元格中,在这个例子中,我将把它放到单元格E2中,然后按下 Shift + Ctrl + Enter 获取第一个唯一值的键,请参见截图:

doc用标准2提取唯一标识符

请注意: 在上面的公式中: B2:B17 是列范围包含要从中提取的唯一值, A2:A17 是包含您基于的标准的列, D2 表示您希望根据和列出唯一值的标准 E1 是您输入的公式之上的单元格。

2。 然后将填充手柄向下拖动到单元格以基于特定标准列出所有唯一值,请参阅屏幕截图:

doc用标准3提取唯一标识符


如果你对复杂的公式不熟练,在这里,我将讨论一个简单的方法来解决它,而不用任何公式。 您可以先按照特定的标准过滤数据,然后应用 选择重复和唯一单元格 的特点 Kutools for Excel 选择唯一的值,然后将它们粘贴到您需要的其他单元格。

Kutools for Excel : 与超过300方便的Excel加载项,在60天免费试用没有限制.

安装后 Kutools for Excel,请按照以下步骤操作:( 立即下载Kutools for Excel! )

1。 首先,请选择您要使用的数据范围,然后单击 数据 > 筛选,然后单击想要根据特定条件过滤数据的单元格旁边的箭头按钮,在展开的列表框中选择要过滤的条件,请参阅截图:

doc用标准4提取唯一标识符

2。 然后点击 OK,所需数据已被过滤掉,并选择列B中要从中提取唯一名称的值,然后单击 Kutools > 选择 > 选择重复和唯一单元格,看截图:

doc用标准5提取唯一标识符

3。 在 选择重复和唯一单元格 对话框中选择 全部唯一(包括1 st副本) 在下面 部分,看截图:

doc用标准6提取唯一标识符

4。 然后点击 Ok 按钮,所有唯一值已被选中,然后请复制这些值并将其粘贴到要列出结果的单元格中,请参阅截图:

doc用标准7提取唯一标识符

立即下载并免费试用Kutools for Excel!


Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Giancarlo · 3 months ago
    Hi! the formula works really well. I would like to add another criterion, i mean, get the unique answers but using two criteria
    • To post as a guest, your comment is unpublished.
      skyyang · 2 months ago
      Hi, Giancarlo,
      to extract unique values based on multiple criteria, any of the below formula can help you: (after pasting the formula, please press Ctrl + Shift + Enter keys together.)
      =IFERROR(INDEX($C$2:$C$11, MATCH(0, COUNTIF(G1:$G$1, $C$2:$C$11)+IF($A$2:$A$11<>$E$2, 1, 0)+IF($B$2:$B$11<>$F$2, 1, 0), 0)), "")
      =INDEX($C$2:$C$11, MATCH(0, IF(($A$2:$A$11=$E$2)*($B$2:$B$11=$F$2), COUNTIF($G$1:$G1, $C$2:$C$11), ""), 0))
      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Konstantin · 4 months ago
    Is there a way to make this work while ALLOWING for duplicate values? For instance, I want all instances of Lucy to be listed in the results.
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      Hello, Konstantin,
      To extract all corresponding values including the duplicates based on a specific cell criteria, the following array formula can help you, see screenshot:
      =IF(ISERROR(INDEX($A$1:$B$17,SMALL(IF($A$1:$A$17=$D$2,ROW($A$1:$A$17)),ROW(1:1)),2)),"",
      INDEX($A$1:$B$17,SMALL(IF($A$1:$A$17=$D$2,ROW($A$1:$A$17)),ROW(1:1)),2))

      After inserting the formula, please press Shift + Ctrl + Enter keys together to get the correct result, and then drag the fill handle down to get all values.
      Hope this can help you, thank you!
  • To post as a guest, your comment is unpublished.
    Ed · 1 years ago
    This has worked great for me with a specific lookup value. However, if I wanted to use a wildcard to look up partial values, how would I do that? For example, if I wanted to lookup all the names associated with KT?

    I am using this function to look up cells that contain multiple text. For example if each product also had a sub-product within the same cell but I was only looking for names associated with the sub-product "elf".

    KTE - elf
    KTE- ball
    KTE - piano
    KTO - elf
    KTO- ball
    KTO - piano
  • To post as a guest, your comment is unpublished.
    ewik · 1 years ago
    For me the formula does not work. I press ctrl shift enter and i still get an error N/A. I would like to add that i prpared exaclty the same data as in tutorial. What is the reason it does not work?
  • To post as a guest, your comment is unpublished.
    Joe Jerz · 1 years ago
    How would I get this formula to return each of the duplicates instead of one of each of the names? For instance, in the example above, how would I get the results column (B:B) to return Lucy, Ruby, Anny, Jose, Lucy, Anny, Tom? I'm using this as a budget tool pulling to specific account summaries from a general ledger. However, several of the amounts and transaction descriptions are duplicates in the general ledger. Once the first of the duplicated values is pulled, no more of them get pulled.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, Joe,
      To extract all corresponding values based on a specific cell criteria, the following array formula can help you, see screenshot:
      =IF(ISERROR(INDEX($A$1:$B$17,SMALL(IF($A$1:$A$17=$D$2,ROW($A$1:$A$17)),ROW(1:1)),2)),"",
      INDEX($A$1:$B$17,SMALL(IF($A$1:$A$17=$D$2,ROW($A$1:$A$17)),ROW(1:1)),2))

      After inserting the formula, please press Shift + Ctrl + Enter keys together to get the correct result, and then drag the fill handle down to get all values.
      Hope this can help you, thank you!
      • To post as a guest, your comment is unpublished.
        Joe Jerz · 1 years ago
        Last Question: If I want the results column to return all values not associated with KTE or KTO (so, D:D would be Tom, Nocol, Lily, Angelina, Genna), how would I do that?
      • To post as a guest, your comment is unpublished.
        Joe Jerz · 1 years ago
        Ok, so it works in the master workbook. There is one exception that I haven't been able to determine the cause of: If the array (in my case, the general ledger that I had beginning in row 3) does not begin in Row 1, the returned values are incorrect. What causes this problem, and which term in the formula fixes it? Thanks again for your help with this!
      • To post as a guest, your comment is unpublished.
        Joe Jerz · 1 years ago
        So far so good. I'm able to duplicate the results in the test sheet, make changes to the array, and then correct the formula to account for the changes I've made. I plan to move this into the master sheet today and see how it works. Thanks for the help!
  • To post as a guest, your comment is unpublished.
    Me · 1 years ago
    Thank You!
  • To post as a guest, your comment is unpublished.
    gon · 1 years ago
    I am getting 0 instead of the expected results, the formula is doing great for data in the same sheet, do you have any solution for data in different sheet ?

    this is my formula

    =IFERROR(INDEX('Switching Data'!$B$7:$B$204,MATCH(0,IF($A$2='Switching Data'!$A$7:$A$204,COUNTIF($A$4:A4,'Switching Data'!$B$7:$B$204),""),0)),0)
    • To post as a guest, your comment is unpublished.
      ANIBAL LUCICHE · 3 months ago
      Hello Gon, I hope you are well. I wonder if you can to resolve this issue. I am getting same error when formula come from different sheet. I will appreciate share the solution if you got it.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, Gon,
      After inserting the formula, you should press Ctrl + Shift + Enter keys together, not just Enter key.
      Please try it, thank you!
  • To post as a guest, your comment is unpublished.
    Mujardin · 1 years ago
    If you get the #N/A error, go to your formula and use Control + Shift + Enter instead of Enter.
  • To post as a guest, your comment is unpublished.
    aditya dhavale · 1 years ago
    Hello, I am getting "#N/A" error at "Match function", can you please guide?
  • To post as a guest, your comment is unpublished.
    aditya · 1 years ago
    I am getting #N/A error at Match function with this formula.Can you please help?
  • To post as a guest, your comment is unpublished.
    Sundari · 1 years ago
    actually I want the cell to reflect "YES" if (AL2="AP" and AK2="AD" and Z2>500000)
  • To post as a guest, your comment is unpublished.
    Sundari · 1 years ago
    =IF(AL2="AP","AP",IF(AK2="AD","AD",IF(Z2>500000,"Yes","No"))) I want "all conditions" to be satisfied to say yes...excel reflecting error in this formula..pls advise
  • To post as a guest, your comment is unpublished.
    Michael · 1 years ago
    this was super helpful, but I keep getting doubles of all the names like this:
    Doe, Jane
    Doe, Jane
    Hoover, Tom
    Hoover, Tom

    How can I stop this?
    • To post as a guest, your comment is unpublished.
      aditya dhavale · 1 years ago
      Hello, I am getting "#N/A" error at "Match function", can you please guide?
  • To post as a guest, your comment is unpublished.
    Andre · 1 years ago
    Hi Ryan. Formulas works great, however when dragging down the first value keeps repeating. I have made sure that COUNTIF references the cell ABOVE the cell with the formula, but still repeats the first value when dragging down? (eg. if the array formula is in C2 then COUNTIF points to cell $C$1:$C$1)
    • To post as a guest, your comment is unpublished.
      Camilla · 1 years ago
      Probably doesn`t work cause you´ve locked the cells - Try to replace $C$1:$C$1 with $C$1:$C1
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Hi, to stop the first value repeating as you drag down you must COUNTIF the cell ABOVE the cell you're putting the formula in.

    E.g if the formula is going in E2 you must type countif($E$1:$E1...
    • To post as a guest, your comment is unpublished.
      Andre · 1 years ago
      Hi Ryan. Formulas works great, however when dragging down the first value keeps repeating. I have made sure that COUNTIF references the cell ABOVE the cell with the formula, but still repeats the first value when dragging down? (eg. if the array formula is in C2 then COUNTIF points to cell $C$1:$C$1)
  • To post as a guest, your comment is unpublished.
    Amanda · 2 years ago
    When using this formula it keeps repeating the first value, how do you make that stop and provide the list of values that equals the product in D2?
  • To post as a guest, your comment is unpublished.
    Barrett · 2 years ago
    This works really well, but whenever the value that it is putting in is duplicated, it only places the value once. For example, if your list had two Lucy's in it, it only brings one Lucy over to the new table. Is there a way to fix this?
  • To post as a guest, your comment is unpublished.
    Claire · 2 years ago
    Thanks for this I have tried this and seems to be working fine intermittently. The issue that keeps repeating is that sometimes only the first matched value will return and is then duplicated when I am dragging down to return all matched values. How do I prevent this? Any suggestions?
  • To post as a guest, your comment is unpublished.
    JeteMc · 2 years ago
    Thank You, This is great!
  • To post as a guest, your comment is unpublished.
    Aileen · 2 years ago
    Thank you for this tutorial! I'm also trying to modify the formula, like the above commentator, but with an AND condition so it meets another conditional criteria (e.g. for this example, I'd like to see only things above a certain threshold). Can you please advise? Thank you!
    • To post as a guest, your comment is unpublished.
      Konfis · 2 years ago
      Hey,
      One way to do it:
      Replace the if formula with sumproduct((condition1=rng1)+(condition2=rng2))*countif(...

      It worked for me. Good luck! By replacing the + with an * you can make it an OR condition, but take good care of the brackets!
  • To post as a guest, your comment is unpublished.
    Jake · 2 years ago
    Hi, thanks for this tutorial, it works perfectly.

    I'm trying to modify it to work with an OR condition, but it doesn't seem to be working - is this possible?

    e.g. =INDEX($B$2:$B$17, MATCH(0, IF(OR($D$2=$A$2:$A$17,$D$2=$B$2:$B$17), COUNTIF($E$1:$E1, $B$2:$B$17), ""), 0))