【问题标题】:Extract unique combinations from Excel sheets从 Excel 工作表中提取独特的组合
【发布时间】:2016-11-18 16:00:23
【问题描述】:

我正在寻找一种方法来从多个具有多列的 Excel 工作表中提取所有唯一组合。例如:

#no.   | fruit    | city    | year    | something else
1      | apple    | London  | 2015    | some text
2      | banana   | London  | 1999    | no text
3      | apple    | Oxford  | 1895    | some text
4      | banana   | London  | 1999    | no text

如何使用 Excel 或 VBA 中的任何函数获取所有唯一行的列表(当然第 1 列除外)?最好是类似脚本的方式,因为工作表包含超过 6000 行不同的信息。

有什么想法吗?

【问题讨论】:

  • 使用删除重复项,它位于数据选项卡下。
  • @ScottCraner 是对的,我尝试了编码,但最简单的选择是删除重复项,将唯一值复制到其他地方,然后确保不要将更改保存在原始工作簿中

标签: excel vba unique


【解决方案1】:

如果您只想使用公式,这里有一些简单的步骤:

1) 在表格末尾添加列。在此列中,像这样连接所有行:

#no.   | fruit    | city    | year    | something else|
1      | apple    | London  | 2015    | some text     |=B2&C2&D2&E2
2      | banana   | London  | 1999    | no text       |
3      | apple    | Oxford  | 1895    | some text     |
4      | banana   | London  | 1999    | no text       |

2) 然后添加另一列来计算和计算重复出现的次数。输入COUNTIF()公式并填写:

no     | fruit    | city    | year    | something else|  Column F  |
1      | apple    | London  | 2015    | some text     |=B2&C2&D2&E2|=COUNTIF($F$2:F2,F2)
2      | banana   | London  | 1999    | no text       |
3      | apple    | Oxford  | 1895    | some text     |
4      | banana   | London  | 1999    | no text       |

如果您使用 criteria=1 过滤最后一列,您可以获得所有唯一的行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    相关资源
    最近更新 更多