跳到主要內容

如何在兩張紙的兩列中查找重複或唯一值?

也許比較同一個工作表中的兩個範圍對於大多數人來說很容易發現重複或唯一值,但是如果兩個範圍在兩個不同的工作表中,您如何快速找出這兩個範圍中的重複和唯一值? 本教程將為您介紹一些快速入門。

將兩個電子表格中的兩個相同的標題列與Excel中的公式進行比較

使用VBA比較兩個電子表格中的兩個範圍

使用Kutools for Excel比較兩個電子表格中的兩個範圍


箭頭藍色右氣泡 將兩個電子表格中的兩個相同的標題列與Excel中的公式進行比較

使用Excel中的公式,您可以比較兩個相同的標題列,如下所示在不同的工作表上,並找到重複的值和唯一值:

1.鍵入此公式 = COUNTIF(Sheet1!$ A:$ A,A1) 在與工作表3中的範圍相鄰的空白單元格中。請參見屏幕截圖:

2。 按 Enter 按鈕,然後拖動填充手柄以填充要與工作表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對您來說很困難,則可以嘗試一下 Excel的Kutools's 比較範圍 的功能。

Excel的Kutools 包括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選項卡為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