跳到主要內容

如何比較兩列並在Excel中突出顯示不匹配的數據?

如下面的屏幕截圖所示,要比較相鄰單元格的兩列並突出顯示不匹配的數據,可以嘗試本文中的方法。

比較兩列,並使用VBA代碼突出顯示不匹配的數據
比較兩列並使用Kutools for Excel突出顯示不匹配的數據


比較兩列,並使用VBA代碼突出顯示不匹配的數據

如上圖所示,您正在比較A列和B列中的數據。請運行以下VBA代碼以突出顯示不匹配的數據。

1。 按 其他 + F11 同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後將以下代碼複製並粘貼到“代碼”窗口中。

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 鍵來運行代碼。 在彈出 Excel的Kutools 對話框中,選擇需要比較的第一列,然後單擊 OK 按鈕。 查看截圖。

4.然後在下一個彈出窗口中選擇第二個比較列 Excel的Kutools 對話框。

5.在下面顯示的屏幕截圖對話框中,要突出顯示不匹配的數據,請單擊 沒有 按鈕。

然後,兩列之間的所有不匹配數據將立即突出顯示。 看截圖:


比較兩列並使用Kutools for Excel突出顯示不匹配的數據

如果您只想找出並突出顯示一列中的單元格值是否存在於另一列中,例如,如下所示的屏幕截圖,則A列中的數字2在B列中不存在。您可以嘗試 比較範圍 的效用 Excel的Kutools.

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選項卡為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