跳到主要内容

如何比较两列并在Excel中突出显示不匹配的数据?

如下面的屏幕截图所示,要比较相邻单元格的两列并突出显示不匹配的数据,可以尝试本文中的方法。

比较两列,并使用VBA代码突出显示不匹配的数据
使用 Kutools for Excel 比较两列并突出显示不匹配的数据


比较两列,并使用VBA代码突出显示不匹配的数据

如上图所示,您正在比较A列和B列中的数据。请运行以下VBA代码以突出显示不匹配的数据。

1。 按 其他 + F11 同时打开 Microsoft Visual Basic应用程序 窗口。

2.在 Microsoft Visual Basic应用程序 窗口中,单击 插页 > 模块。 然后将以下代码复制并粘贴到“代码”窗口中。

VBA代码:比较两列并突出显示不匹配的数据

Sub Dyeware()
    Dim xRg1 As Range
    Dim xRg2 As Range
    Dim xTxt As String
    Dim xCell1 As Range
    Dim xCell2 As Range
    Dim I As Long
    Dim J As Integer
    Dim xLen As Integer
    Dim xDiffs As Boolean
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
lOne:
    Set xRg1 = Application.InputBox("Range A:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg1 Is Nothing Then Exit Sub
    If xRg1.Columns.Count > 1 Or xRg1.Areas.Count > 1 Then
        MsgBox " Multiple ranges or columns have been selected ", vbInformation, "Kutools for Excel"
        GoTo lOne
    End If
lTwo:
    Set xRg2 = Application.InputBox("Range B:", "Kutools for Excel", "", , , , , 8)
    If xRg2 Is Nothing Then Exit Sub
    If xRg2.Columns.Count > 1 Or xRg2.Areas.Count > 1 Then
        MsgBox "Multiple ranges or columns have been selected", vbInformation, "Kutools for Excel"
        GoTo lTwo
    End If
    If xRg1.CountLarge <> xRg2.CountLarge Then
       MsgBox "Two ranges must have the same numbers of cells ", vbInformation, "Kutools for Excel"
       GoTo lTwo
    End If
    xDiffs = (MsgBox("Click Yes to highlight matched data, click No to highlight unmatched data ", vbYesNo + vbQuestion, "Kutools for Excel") = vbNo)
    Application.ScreenUpdating = False
    xRg2.Interior.ColorIndex = xlNo
    xRg1.Interior.ColorIndex = xlNo
    For I = 1 To xRg1.Count
        Set xCell1 = xRg1.Cells(I)
        Set xCell2 = xRg2.Cells(I)
        If xCell1.Value = xCell2.Value Then
            If Not xDiffs Then
                xCell1.Interior.Color = vbRed
                xCell2.Interior.Color = vbRed
            End If
        Else
            If xDiffs Then
                xCell1.Interior.Color = vbRed
                xCell2.Interior.Color = vbRed
            End If
        End If
    Next
    Application.ScreenUpdating = True
End Sub

3。 按 F5 键来运行代码。 在弹出 Kutools for Excel 对话框中,选择需要比较的第一列,然后单击 OK 按钮。 查看截图。

4.然后在下一个弹出窗口中选择第二个比较列 Kutools for Excel 对话框。

5.在下面显示的屏幕截图对话框中,要突出显示不匹配的数据,请单击 没有 按钮。

然后,两列之间的所有不匹配数据将立即突出显示。 看截图:


使用 Kutools for Excel 比较两列并突出显示不匹配的数据

如果您只是想找出并突出显示一列中的单元格值是否存在于另一列中,例如,如下面的屏幕截图所示,则B列中不存在A列中的数字2。 比较范围 实用程序 Kutools for Excel.

1。 点击 库工具 > 插页选择相同和不同的单元格。 看截图:

2.在 选择相同和不同的单元格 对话框,您需要配置如下:

2.1选择包含未匹配单元格的第一列,您将在其中突出显示 寻找价值 在盒子里
2.2在列表中选择要比较的第二列 根据 框;
2.3在 基于 setcion,选择 单细胞 选项;
2.3选择 不同的价值观 在选项 找到最适合您的地方 部分;
2.4在 处理结果 部分,检查 填充背景色 框,然后从下拉列表中指定背景色;
2.5点击 OK 按钮。 看截图:

3.然后弹出一个对话框,告诉您仅在A列而不是B列中有多少个单元格,单击OK按钮,然后在A列中选择了所有匹配的单元格。

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


相关文章:

最佳办公生产力工具

🤖 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 (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi Bro,
Thank you for your reply.
I checked this link and I don't see what iam expecting.. if in A1 clm we have 'Man' and A2 as 'Mon'. In that, 'o' only different. So, I need like the 'o' should be highlighted. Other text should be shown as normal text.
This comment was minimized by the moderator on the site
Hi, It's awesome and very useful!!!!!!!!

Also, I have a doubt about this. In 'A1', I have text as 'Hi Man' and in 'B1', I Have text as 'Ha Man'. So when I run the Macron, I need the result as in B1 'Ha Man' (The "a" only should be highlighted and other text should be in normal).

Please sort out this issue Bro!!!
This comment was minimized by the moderator on the site
Good day,
The VBA code in below article can do you a favor. Please follow the link.
How To Compare Two Strings For Similarity Or Highlight Differences In Excel?
https://www.extendoffice.com/documents/excel/3716-excel-compare-two-strings-highlight-differences-for-similarity.html#a2
This comment was minimized by the moderator on the site
hi
i have some doubt in vba
This comment was minimized by the moderator on the site
Hi,
Please let me know your doubt.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations