跳到主要内容

如何在两张纸的两列中查找重复或唯一值?

也许比较同一个工作表中的两个范围对于大多数人来说很容易发现重复或唯一值,但是如果两个范围在两个不同的工作表中,您如何快速找出这两个范围中的重复和唯一值? 本教程将为您介绍一些快速入门。

将两个电子表格中的两个相同的标题列与Excel中的公式进行比较

使用VBA比较两个电子表格中的两个范围

使用 Kutools for Excel 比较两个电子表格中的两个范围


箭头蓝色右气泡 将两个电子表格中的两个相同的标题列与Excel中的公式进行比较

使用Excel中的公式,您可以比较两个相同的标题列,如下所示在不同的工作表上,并找到重复的值和唯一值:

1.键入此公式 = COUNTIF(Sheet1!$ A:$ A,A1) 在与工作表3中的范围相邻的空白单元格中。请参见屏幕截图:

2。 按 输入 按钮,然后拖动填充手柄以将要与工作​​表1中的范围进行比较的范围填充。(数字零表示在两个范围中重复的值,数字1表示在Sheet3中的唯一值,但在Sheet1中不是)

提示:

1.此公式只能比较两个电子表格中具有相同标题的两列。

2.如果要在Sheet1中找到唯一值,而不在Sheet3中找到唯一值,则需要输入上面的公式=COUNTIF(Sheet3!$ A:$ A,A1) 进入Sheet1。


箭头蓝色右气泡 使用VBA比较两个电子表格中的两个范围

1.按住 ALT 按钮并按下 F11 在键盘上打开一个 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将VBA复制到模块中。

VBA:比较两个电子表格中的两个范围

Sub CompareRanges()'更新20130815昏暗的WorkRng1作为范围,WorkRng2作为范围,Rng1作为范围,Rng2作为范围xTitleId =“ KutoolsforExcel”设置WorkRng1 = Application.InputBox(“范围A:”,xTitleId,“”,类型:= 8 )设置WorkRng2 = Application.InputBox(“ Range B:”,xTitleId,Type:= 8)对于WorkRng1中的每个Rng1 rng1Value = WorkRng1中的每个Rng2.Value如果rng2Value = Rng1.Value,则Rng2.Interior.Color = VBA .RGB(1,255,0)结束时退出,如果下一个下一个结束子

3。 点击 运行 按钮或按下 F5 运行VBA。

4.屏幕上会显示一个对话框,您应该选择一个要比较的范围。 看截图:

5。 点击 Ok 此时将显示另一个对话框,供您选择第二个范围。 看截图:

6。 点击 Ok,范围A和范围B中的重复值都用范围A中的红色背景突出显示。请参见屏幕截图:

提示:使用此VBA,您可以在相同和不同的工作表中比较两个范围。


箭头蓝色右气泡 使用 Kutools for Excel 比较两个电子表格中的两个范围

如果公式对您来说不方便,而VBA对您来说很困难,则可以尝试一下 Kutools for Excel's 比较范围 功能。

Kutools for Excel 包括300多个便捷的Excel工具。 30天免费试用,不受限制。 立即获取

请申请 比较范围 通过单击功能 库工具 > 比较范围。 看截图:

与不同工作表中的两列进行比较:

1。 点击 库工具 > 比较范围,屏幕上将显示一个对话框。 看截图:

2.指定范围和规则,请执行以下操作:

将比较保留在相同范围内 取消选中,然后通过单击选择两个范围 范围A 范围B,请参见屏幕截图:

在“规则”下的下拉框中指定要查找的相同值或不同值;

3。 点击 Ok。 弹出对话框告诉您选择了相同的值。

4。 点击 Ok 弹出对话框中的按钮。 在范围A中选择两个范围之间的相同值。

比较点差工作表中的两个范围

如果在两个电子表格中有两个范围,如下所示,并且您想比较它们并找出不同的值,则可以执行以下操作:

1。 点击 库工具 > 比较范围,屏幕上将显示一个对话框。

2.指定范围和规则,请执行以下操作:

离开 在相同范围内比较 取消选中,然后通过单击选择两个范围 范围A范围B;

在“规则”下的下拉框中指定要查找的其他值;

检查我的数据是否有标题 in 附加选项 部分;

3。 点击 Ok。 弹出对话框告诉您选择了相同的值。

4。 点击 Ok 弹出对话框中的按钮。 选择范围A中的不同值。 看截图:

如果要在Sheet2的范围B中查找不同的值,则需要交换两个范围。

比较范围 函数还可以比较同一张纸中的范围。 单击此处以了解有关比较范围的更多信息。


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is good. It highlights only one sheet duplicate item. But I need to highlight both the sheet where duplicate items are
This comment was minimized by the moderator on the site
You need to add a second command inside the THEN statement.


Try this;

Sub CompareRanges()
'Update 20130815
Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range
xTitleId = "Enter Range for Comparison"
Set WorkRng1 = Application.InputBox("Range A:", xTitleId, "", Type:=8)
Set WorkRng2 = Application.InputBox("Range B:", xTitleId, Type:=8)
For Each Rng1 In WorkRng1
rng1Value = Rng1.Value
For Each Rng2 In WorkRng2
If rng1Value = Rng2.Value Then
Rng1.Interior.Color = VBA.RGB(255, 0, 0)
Rng2.Interior.Color = VBA.RGB(255, 0, 0)
Exit For
End If
Next
Next
End Sub
This comment was minimized by the moderator on the site
Hi,morning, I need to look up for a range of values in all the available worksheets, and in case there is any matches, then colour the value on the original range. I have tried the following code: Sub Compare3() Dim WorkRng1 As Range Dim WorkRng2 As Range Dim Rng1 As Range Dim Rng2 As Range Dim DataRange As Range Dim ws As Worksheet xTitleId = "Buscar coincidencias" Set WorkRng1 = Application.InputBox("Seleccionar equipos con cambios:", xTitleId, "", Type:=8) Set WorkRng2 = Range("B1" & LastRow) For Each Rng1 In WorkRng1 rng1Value = Rng1.Value For Each ws In ActiveWorkbook.Worksheets For Each Rng2 In WorkRng2 If rng1Value = Rng2.Value Then Rng1.Interior.Color = VBA.RGB(200, 250, 200) Exit For End If Next Next Next End Sub But it does not make any changes when there are matches.... Could someone help?? Many thanks, Have a good day
This comment was minimized by the moderator on the site
Hi, I need to look up for a range of values in all the available worksheets, and in case there is any matches, then colour the value on the original range. I have tried the following code: Sub Compare3() Dim WorkRng1 As Range Dim WorkRng2 As Range Dim Rng1 As Range Dim Rng2 As Range Dim DataRange As Range Dim ws As Worksheet xTitleId = "Buscar coincidencias" Set WorkRng1 = Application.InputBox("Seleccionar equipos con cambios:", xTitleId, "", Type:=8) Set WorkRng2 = Range("B1" & LastRow) For Each Rng1 In WorkRng1 rng1Value = Rng1.Value For Each ws In ActiveWorkbook.Worksheets For Each Rng2 In WorkRng2 If rng1Value = Rng2.Value Then Rng1.Interior.Color = VBA.RGB(200, 250, 200) Exit For End If Next Next Next End Sub But it does not make any changes when there are matches.... Could someone help?? Many thanks, Have a good day
This comment was minimized by the moderator on the site
Hi, the code is working but the entire range is getting highlighted even if there are no duplicate values. Help!
This comment was minimized by the moderator on the site
how to compare datas between two different excel sheets?
This comment was minimized by the moderator on the site
Hi, How can I find out the word difference between two columns in excel
This comment was minimized by the moderator on the site
How to Find out same names from different columns. If one column contains 2000 records and second one contains 20000 records, so how to compare and differentiate that names? Thanks,
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations