Skip to main content

How to find duplicate or unique values in two columns of two worksheets?

Author Sun Last modified

Maybe compare two ranges in the same worksheet and find out the duplicate or unique values is easy for most of you, but if the two ranges are in the two different worksheets, how can you quickly find out the duplicate and unique values in these two ranges? This tutorial will introduce some quick cuts for you.

Use formula to compare two same header columns in two spread sheets

Use VBA to compare two ranges in two spread sheets

Use Kutools for Excel to compare two ranges in two spread sheets


Use formula to compare two same header columns in two spread sheets

With the formula in Excel, you can compare two same header columns as shown as below on different sheets and find the duplicate and unique values:

find duplicate or unique values data 1 find duplicate or unique values data 2

1. Typing the following formula in a blank cell which is adjacent to the range in Sheet 3.

=COUNTIF(Sheet1!$A:$A, A1)

find duplicate or unique values formula 1

2. Press "Enter" button on the keyboard, and then drag the fill handle to fill the range you want to compare with the range in Sheet 1. (Number 0 means duplicate values in two ranges, and Number 1 means unique values in Sheet3, but not in Sheet1)

find duplicate or unique values formula 2

Tips:

1.This formula only can compare two columns with the same header in two spreadsheets.

2. If you want to find the unique values in Sheet1, but not in Sheet3, you need to enter the below formula in Sheet1.

=COUNTIF(Sheet3!$A:$A, A1)

Use VBA to compare two ranges in two spread sheets

1. Hold "ALT" button and press" F11" on the keyboard to open a "Microsoft Visual Basic for Application" window.

2. Click "Insert" > "Module", and copy the VBA into the module.

VBA: Compare two ranges in two spreadsheets

Sub CompareRanges()
'Update 20130815
Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range
xTitleId = "KutoolsforExcel"
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)
            Exit For
        End If
    Next
Next
End Sub

3. Click "Run" button or press "F5" to run the VBA.

4. There is a dialog displayed on the screen, and you should select one range you want to compare with. See screenshot:

find duplicate or unique values vba 1

5. Click "Ok" and another dialog is displayed for you to select the second range. See screenshot:

find duplicate or unique values vba 2

6. Click "Ok", and the duplicate values both in Range A and in Range B are highlighted with the red background in Range A. See screenshot:

find duplicate or unique values vba 3

Tips: With this VBA, you can compare two ranges both in the same and different worksheets.


Use Kutools for Excel to compare two ranges in two spread sheets

If formula is not convenient for you, and VBA is difficult for you, you can have a try on "Kutools for Excel"'s "Compare Ranges" function.

"Kutools for Excel" includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. "Get it Now"

Please apply "Compare Ranges" function by clicking "Kutools" > "Compare Ranges". See screenshot:

Compare with two columns in different sheets:

1. Click "Kutools" > "Compare Ranges", a dialog is displayed in the screen. See screenshot:

find duplicate or unique values kutools 2

2. Specify the ranges and rules, do as follows:

"Leave Compare in same range" uncheck, and select two ranges by clicking "Range A" and" Range B", see screenshot:

find duplicate or unique values kutools 3

find duplicate or unique values kutools 4

Specify the same values or different values you want to find in the drop-down box under Rules;

3. Click "Ok". A pop-up dialog tells you the same values are selected.

find duplicate or unique values kutools 5

4. Click "Ok" button in the pop-up dialog. The same values between two ranges are selected in Range A.

Compare two ranges in two worksheets

If you have two ranges in two spreadsheets as shown as below, and you want to compare them and find out the different values, you can do as follows:

1. Click "Kutools" > "Compare Ranges", a dialog is displayed in the screen.

2. Specify the ranges and rules, do as follows:

Leave "Compare in same range" uncheck, and select two ranges by clicking" Range A" and "Range B";

Specify the different values you want to find in the drop-down box under Rules;

"Check My data has headers" in "Options" section;

3. Click "Ok". A pop-up dialog tells you the same values are selected.

4. Click "Ok" button in the pop-up dialog. The different values in Range A are selected. See screenshot:

find duplicate or unique values kutools 6

If you want to find out the different values in Range B of Sheet2, you need to swap the two ranges.


Relative articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!