How to compare columns in excel for duplicates

When we use a worksheet, sometimes we need to compare two columns and find the same values. For example, I have two long columns of student names, and now, I want to compare them and find out the same names. If I compare them cell by cell, it will be tiresome and waste a lot of time. Are there any quick ways to finish this task?

Find duplicate values in two columns with Formula

Find duplicate values in two columns with VBA code

Quickly find duplicate values in two columns with Kutools for Excel

How to compare columns in excel for duplicates

Quickly find duplicate values in one column with Kutools for Excel

How to compare columns in excel for duplicates

Find duplicate values in two columns with Formula

Look at the following screenshot, I have column A (A2:A15) and column C (C2:C13) which contain some duplicate names.

How to compare columns in excel for duplicates

By using a formula, we can compare two columns and display the duplicate values. Please do with the following steps:

1. In cell B2, input this formula: =IF(ISERROR(MATCH(A2,$C$2:$C$13,0)),"",A2).

How to compare columns in excel for duplicates

Note: In the above formula: A2 is the column which you want to be compared. $C$2:$C$13 is the range that you want to be compared with. You can change the variables for what you are using.

2. Press the Enter key. Select cell B2, and then drag the fill handle over cell B15. And all of the duplicate names will be displayed in column B. See screenshot:

How to compare columns in excel for duplicates

Find duplicate values in two columns with VBA code

The following VBA code can also help you to find out the duplicate values between two columns.

1. Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be displayed, click Insert > Module, and input the following code into the Module:

VBA code: find duplicates from two columns

Sub Compare() Dim Range1 As Range, Range2 As Range, Rng1 As Range, Rng2 As Range, outRng As Range xTitleId = "KutoolsforExcel" Set Range1 = Application.Selection Set Range1 = Application.InputBox("Range1 :", xTitleId, Range1.Address, Type:=8) Set Range2 = Application.InputBox("Range2:", xTitleId, Type:=8) Application.ScreenUpdating = False For Each Rng1 In Range1 xValue = Rng1.Value For Each Rng2 In Range2 If xValue = Rng2.Value Then If outRng Is Nothing Then Set outRng = Rng1 Else Set outRng = Application.Union(outRng, Rng1) End If End If Next Next outRng.Select Application.ScreenUpdating = True End Sub

2. Click

How to compare columns in excel for duplicates
button to execute the code, in the popped out box select Range 1 that you want to compare.

How to compare columns in excel for duplicates

3. Click OK and go on selecting Range 2 that you will be compared with.

How to compare columns in excel for duplicates

4. Then click OK, and the duplicate values both in column A and column C have been selected in column A.

How to compare columns in excel for duplicates

Note: If you want to select the duplicates from column C, you just need to swap the two selected columns.

Quickly find duplicate values in two columns with Kutools for Excel

With the help of Kutools for Excel, you can find the duplicate values quickly and comfortably.

After free installing Kutools for Excel, please do as below:

Click Kutools > Select > Select Same & Different Cells.

How to compare columns in excel for duplicates

1. In the Select Same & Different Cells dialog box, do the following operations:

(1.) Click the first

How to compare columns in excel for duplicates
button to select the source column to be compared, then click the second
How to compare columns in excel for duplicates
button to select the column you are compared with;

(2.) Choose Each row under the Based on section;

(3.) Then select Same Values fromt he Find section;

(4.) At last, you can choose one background or font color to highlight the same cells under the Processing of resuts section as you need.

How to compare columns in excel for duplicates

2. Then click OK, and the same values both in column A and column B have been selected in column A.

How to compare columns in excel for duplicates

With this utility, you can also find the different values between two columns.

Notes:

  • My data has headers: If the data you are compared has headers, you can check this option, and the headers will not be compared.
  • Select entire rows: With this option, the entire rows which contain the same values will be selected.
  • Case Sensitive: Checking this option, you will compare the columns with case sensitive.
  • The two comparing ranges must contain the same number of columns.
  • If you want to select the duplicates from column C, you just need to swap the two selected columns.

Demo: Quickly find and highlight duplicate values in two columns

Quickly find duplicate values in one column with Kutools for Excel

After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)

Sometimes, you may want to find the duplicate values in a column, the Kutools for Excel also can help you quickly handle it.

1. Select the column you want to find duplicate values, click Kutools > Select > Select Duplicate & Unique Cells.

How to compare columns in excel for duplicates

2. In the Select Duplicate & Unique Cells dialog, check Duplicates or All duplicates option as you need, and at the same time, you can decide to highlight the duplicates with background or font color or not in Processing of results section.

How to compare columns in excel for duplicates

3. Click Ok, a dialog pops out to remind you the number of selected duplicate cells, click OK to close it, and the duplicates are selected and highlighted.

How to compare columns in excel for duplicates

  Select Duplicate & Unique Cells

Related Article:

How to find unique values between two columns in excel?

This tutorial talks about how to compare two columns in Excel, which is a normal Excel job in our daily work. Comparing two columns can be done in different ways in Excel, such as comparing two columns row by row or cells by cells, comparing two columns for highlighting matches or differences, etc. Here this article covers most possible scenarios of the comparing two columns you might meet, and hope it can help you.

Note

In this tutorial, it provides some example data for better explaining the methods on comparing two columns in various of cases. Based on your dataset, you may need to change or adjust some contents (references), however, the basic principles would remain the same. Or directly download the samples of each cases if you only want to verify if the methods work or not.

Below is a data set where I need to check in the same row whether the names in column A are same with those in column B or not.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

1.1 Compare cells in the same row for exactly match

Generally, if you want to compare two columns row by row for exactly matching, you can use below formula:

How to compare columns in excel for duplicates

Press Enter key and drag fill handle down to cell D8. If the formula returns TRUE, the values of two columns are totally same, if returns FALSE, they are different.

How to compare columns in excel for duplicates

1.2 Compare cells in the same row for exactly or case insensitive match (using IF formula)

If you want to compare two columns row by row for case insensitive, or get more description such as Match, Mismatch, you can use the IF function.

Comparing cells in same row for exactly match

If you want to use the texts “Match” and “Mismatch” to describe the comparing results, please use below formula:

=IF(EXACT(B2,C2),"Match","Mismatch")

How to compare columns in excel for duplicates

Press Enter key to get the first result, then drag auto fill handle to cell D8.

How to compare columns in excel for duplicates

Comparing cells in same row for case insensitive match

If you want to compare cells for case insensitive, you can use below formula:

=IF(B2=C2,"Match","Mismatch")

How to compare columns in excel for duplicates

Press Enter key to get the first result, then drag auto fill handle to cell E8.

How to compare columns in excel for duplicates

Remark

In above formulas, you can change the texts “Match” and “Mismatch” to your own description.

1.3 Compare cells in the same row and highlight matching or mismatching data (using Conditional Formatting)

If you want to highlight the matching or different values, the Conditional Formatting feature can help you.

1. Select the two columns that are used to compared with (B2:C8, excluding column headers), then click Home > Conditional Formatting > New Rule.

How to compare columns in excel for duplicates

2. In the popping New Formatting Rule dialog, click to choose Use a formula to determine which cells to format in the Select a Rule Type section, then type =$B2=$C2 into the textbox of Format values where this formula is true.

How to compare columns in excel for duplicates

3. Now click Format to display the Format Cells dialog, then under Fill tab, choose one color you need to highlight the matches.

Or you can change the font size, font size, cell borders, or the number format to outstand the matches as you need in other tabs.

How to compare columns in excel for duplicates

4. Click OK > OK to close the dialogs, then the cells in the same row will be highlighted if they are same.

How to compare columns in excel for duplicates

If you want to highlight the mismatch values, you can use this in the =$B2<>$C2 into the Format values where this formula is true textbox in the Edit Formatting Rule dialog.

How to compare columns in excel for duplicates

Then the differences of two columns in the same row will be highlighted with a specified color.

How to compare columns in excel for duplicates

1.4 Compare two columns row by row and highlight mismatch values (using VBA)

If you want to compare two columns row by row with VBA code, this tutorial satisfies you.

1. Enable the worksheet that contains the two columns used to compare, press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window.

2. In the popping dialog, click Insert > Module.

How to compare columns in excel for duplicates

3. Then copy and paste below macro in the new module script.

VBA: Compare two columns row by row and highlight the differences

Sub ExtendOffice_HighlightColumnDifferences() 'UpdatebyKutools20201016 Dim xRg As Range Dim xWs As Worksheet Dim xFI As Integer On Error Resume Next SRg: Set xRg = Application.InputBox("Select two columns:", "Kutools for Excel", , , , , , 8) If xRg Is Nothing Then Exit Sub If xRg.Columns.Count <> 2 Then MsgBox "Please select two columns" GoTo SRg End If Set xWs = xRg.Worksheet For xFI = 1 To xRg.Rows.Count If Not StrComp(xRg.Cells(xFI, 1), xRg.Cells(xFI, 2), vbBinaryCompare) = 0 Then xWs.Range(xRg.Cells(xFI, 1), xRg.Cells(xFI, 2)).Interior.ColorIndex = 7 'you can change the color index as you need. End If Next xFI End Sub

How to compare columns in excel for duplicates

4. press F5 key to run the code, then a dialog pops out for selecting the two columns.

How to compare columns in excel for duplicates

5. Click OK. Then the differences of two columns have been highlighted with a background color.

How to compare columns in excel for duplicates

Remark

You can change the highlighting color based on your own need by changing the color index in the code, the Color index reference:

How to compare columns in excel for duplicates

In this part, the data set is shown as below, and you want to find all values which are in both column B and column C simultaneously, or, find the values only in column B.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

2.1 Compare two columns cells by cells and display comparing results in another column (using formula)

Here you can use the formula which is combined with IF and COUNTIF function to compare two columns and find the values that are in column B but not in column C.

=IF(COUNTIF($C$2:$C$8, $B2)=0, "No in C", "Yes in C")

How to compare columns in excel for duplicates

Press Enter key and drag autofill handle over to cell D8.

How to compare columns in excel for duplicates

Remark

1. This formula compares two columns without case sensitive.

2. You can change the description “No in C” and “Yes in C” to others.

3. If you want to compare two entire columns, change the fixed range $C$2:$C$8 to $C:$C.

2.2 Compare and highlight duplicate or unique data (using Conditional Formatting)

The Conditional Formatting feature in Excel is powerful, here you can use it to compare two columns cells by cells and then highlight the differences or matches as you need.

Highlight all duplicates or unique values in two columns

1. Select two columns that you will compare with, then click Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.

How to compare columns in excel for duplicates

2. In the popping Duplicate Values dialog, choose a highlighting format you need from the drop-down list of values with.

How to compare columns in excel for duplicates

3. Click OK. Then the duplicates in two columns have been highlighted.

How to compare columns in excel for duplicates

Remark

If you want to highlight the unique values (the differences) in two columns, also click Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values to display the Duplicate Values dialog, change the Duplicate to Unique in the left drop-down list, then choose another format from the values with drop-down list, click OK.

How to compare columns in excel for duplicates

The unique values will be highlighted.

How to compare columns in excel for duplicates

Find and highlight the values in column B if it is also in column C

If you want to highlight the values in column B that are also in column C, the Conditional Formatting feature also can do you a favor.

1. Select the column B2:B8, click Home > Conditional Formatting > New Rule.

How to compare columns in excel for duplicates

2. In the New Formatting Rule dialog, choose Use a formula to determine which cells to format from the Select a Rule Type section, then type =COUNTIF($C$2:$C$8, $B2)>0 into the textbox of Format values where this formula is true.

How to compare columns in excel for duplicates

3. click Format to go to the Format Cells dialog, under Fill tab, choose one color to highlight the matches.

You can use other formats to highlight the values in Font, Number, Border tabs.

How to compare columns in excel for duplicates

4. Click OK > OK. Then the values in column B that also exist in column C have been highlighted with specified color.

How to compare columns in excel for duplicates

If you want to highlight the values that only in column B but not in column C, repeat above steps, but change the formula in step 2 to =COUNTIF($C$2:$C$8, $B2)=0 in the New Formatting Rule dialog.

How to compare columns in excel for duplicates

Then choose another color to format the values.

How to compare columns in excel for duplicates

Remark

Here the Conditional Formatting compares two columns without case insensitive.

2.3 Compare and select or highlight duplicate or unique data (using a handy tool)

Sometimes, after comparing two columns, you may take other actions on the matches or difference, such as selection, deletion, copy and so on. In this case, a handy tool – Select Same & Different Cells of Kutools for Excel can directly select the matches or difference for better doing next operation, also can directly highlight the values.

How to compare columns in excel for duplicates

After free installing Kutools for Excel, please do as below:

1. Click Kutools > Select > Select Same & Different Cells.

How to compare columns in excel for duplicates

2. Then in the Select Same & Different Cells dialog, please do as below:

1) In the Find values in and According to sections, choose two columns that you want to compare with;

2) Choose Each row option;

3) Choose Same values or Different Values as you need;

4) If you want to highlight the values, choose the color you need.

How to compare columns in excel for duplicates

3. Click Ok, a dialog pops out to remind you the number of values that have been found, click OK to close the dialog. And at the same time, the values have been selected, now you can delete or copy or do other operations.

How to compare columns in excel for duplicates

If you check the Fill backcolor and Fill font color checkboxes, the result is shown as this:

How to compare columns in excel for duplicates

Remark

If you want to compare with case sensitive, check the Case sensitive option.

This tool supports to compare two columns in different worksheets.

2.4 Compare two columns and list exact duplicates in another column (using VBA code)

If you want to list the matching values in another column after comparing two columns cell by cell, here the below macro code can help you.

1. Enable the sheet that you want to compare two columns, then press Alt + F11 keys to display the Microsoft Visual Basic for Applications window.

2. Click Insert > Module in the Microsoft Visual Basic for Applications window.

How to compare columns in excel for duplicates

3. Then copy and paste below code to the new blank module script.

VBA: List duplicates in beside column after comparing two columns

Sub ExtendOffice_FindMatches() 'UpdatebyKutools20201019 Dim xRg, xRgC1, xRgC2, xRgF1, xRgF2 As Range Dim xIntSR, xIntER, xIntSC, xIntEC As Integer On Error Resume Next SRg: Set xRgC1 = Application.InputBox("Select first column:", "Kutools for Excel", , , , , , 8) If xRgC1 Is Nothing Then Exit Sub If xRgC1.Columns.Count <> 1 Then MsgBox "Please select single column" GoTo SRg End If SsRg: Set xRgC2 = Application.InputBox("Select the second column:", "Kutools for Excel", , , , , , 8) If xRgC2 Is Nothing Then Exit Sub If xRgC2.Columns.Count <> 1 Then MsgBox "Please select single column" GoTo SsRg End If Set xWs = xRg.Worksheet For Each xRgF1 In xRgC1 For Each xRgF2 In xRgC2 If xRgF1.Value = xRgF2.Value Then xRgF2.Offset(0, 1) = xRgF1.Value Next xRgF2 Next xRgF1 End Sub

How to compare columns in excel for duplicates

4. Press F5 key to run the code, there are two dialogs popping out one by one for you to select two columns separately.

Note: Please select the left column firstly, then select the right column in the second dialog, or the duplicates will replace original data in the second column.

How to compare columns in excel for duplicates
How to compare columns in excel for duplicates

5. Click OK > OK, then the matches have been automatically listed in the right column of the two columns.

How to compare columns in excel for duplicates

Remark

The VBA code compares two columns with case sensitive.

2.5 Compare two columns and highlight duplicates (using VBA code)

If you want to compare two columns cell by cell and then highlight the matches, you can try below code.

1. Enable the sheet that you want to compare two columns, then press Alt + F11 keys to display the Microsoft Visual Basic for Applications window.

2. Click Insert > Module in the Microsoft Visual Basic for Applications window.

How to compare columns in excel for duplicates

3. Copy below macro code and paste them in the new blank Module script.

VBA: Compare two columns and highlight duplicates

Sub ExtendOffice_CompareTwoRanges() 'UpdatebyKutools20201019 Dim xRg, xRgC1, xRgC2, xRgF1, xRgF2 As Range SRg: Set xRgC1 = Application.InputBox("Select the column you want compare according to", "Kutools for Excel", , , , , , 8) If xRgC1 Is Nothing Then Exit Sub If xRgC1.Columns.Count <> 1 Then MsgBox "Please select a single column" GoTo SRg End If SsRg: Set xRgC2 = Application.InputBox("Select the column you want to highlight duplicates in:", "Kutools for Excel", , , , , , 8) If xRgC2 Is Nothing Then Exit Sub If xRgC2.Columns.Count <> 1 Then MsgBox "Please select a single column" GoTo SsRg End If For Each xRgF1 In xRgC1 For Each xRgF2 In xRgC2 If xRgF1.Value = xRgF2.Value Then xRgF2.Interior.ColorIndex = 38 '(you can change the color index as you need) End If Next Next End Sub

How to compare columns in excel for duplicates

4. Press F5 key to run the code. In the first popping out dialog, select the column that you want to compare duplicate values according to.

How to compare columns in excel for duplicates

5. Click OK. In the second dialog, select the column you want to highlight duplicate values in.

How to compare columns in excel for duplicates

6. Click OK. Now the duplicates in the second column have been highlighted with a background color after comparing with first column.

How to compare columns in excel for duplicates

Remark

1. The code compares columns with case sensitive.

2. You can change the highlighting color based on your own need by changing the color index in the code, the Color index reference:

How to compare columns in excel for duplicates

Sometimes, you may want to compare more than two columns in the same row, such as the data set as below screenshot shown. Here in this section, it lists different methods on comparing multiple columns.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

3.1 Find full matches in all cells in the same row (using IF formula)

To find full matches across columns in the same row, the below IF formula can help you.

=IF(AND(B2=C2, B2=D2), "Full match", "Not")

 

How to compare columns in excel for duplicates

If the cells in the same row match each other, “Full match” is displayed, or “Not” is displayed.

Press Enter key to get the first comparing result, then drag auto fill handle over to cell E7.

How to compare columns in excel for duplicates

Remark

1. The formula compares columns without case sensitive.

2. If you need to compare more or equal to three columns, you can use below formula:

=IF(COUNTIF($B2:$D2, $B2)=3, "Full match", "Not")

 

How to compare columns in excel for duplicates

In the formula, 3 is the number of columns, you can change it to meet your need.

3.2 Find matched in any two cells in the same row (using IF formula)

Sometimes, you want to find out if any two columns in the same row are matched, you can use below IF formula.

=IF(OR(B2=C2, C2=D2, B2=D2), "Match", "Not")

 

How to compare columns in excel for duplicates

In this formula, you need to compare any one pair of cells in the same row. “Match” indicates that there are any two cells matched, if there are no cells matching, the formula display “Not”, you can change the texts as you need.

Press Enter key, and drag fill handle over to cell E7.

How to compare columns in excel for duplicates

Remark

1. This formula does not support case insensitive.

2. If there are many columns needed to compare, to compare any one pair of cells in the formula may be too long. In this case, you can consider to use below formula which combines the IF and COUNTIF functions.

=IF(COUNTIF(C11:E11,B11)+COUNTIF(D11:E11,C11)+(D11=E11)=0,"Not","Match")

 

How to compare columns in excel for duplicates

3.3 Find full matches in all cells in the same row and highlight (using Conditional Formatting)

If you want to highlight the rows that all cells are matching with each other, you can use the Conditional Formatting feature in Excel.

1. Select the range that you use, then click Home > Conditional Formatting > New Rule.

How to compare columns in excel for duplicates

2. In the New Formatting Rule dialog, choose Use a formula to determine which cells to format from the Select a Rule Type section, then you can use one of below formulas in the Format values where this formula is true textbox.

Or

 

How to compare columns in excel for duplicates

Note: If the number of columns is more than three, supposing is 5, the formulas should be changed to:

=AND($B2=$C2, $B2=$D2, $B2=$E2, $B2=$F2)

Or

3. Click Format button to go to the Format Cells dialog, then choose one fill color or other cell formatting to outstand the rows.

How to compare columns in excel for duplicates

4. Click OK > OK, now only rows within which all cells are matching will be highlighted.

How to compare columns in excel for duplicates

Remark

Above formulas do not support case sensitive.

3.4 Compare multiple columns and highlight row differences

If you want to highlight the row differences, which means it compares column cells one by one, and find the different cells according to the first column, you can use Excel built-in feature-Go To Special.

1. Select the range that you want to highlight row differences, and click Home > Find & Select > Go To Special.

How to compare columns in excel for duplicates

2. In the popping Go To Special dialog, check Row differences option.

How to compare columns in excel for duplicates

3. Click OK. Now the row differences have been selected.

How to compare columns in excel for duplicates

4. Now keep the cells selected, click Home > Fill Color to select one color from the drop-down menu.

How to compare columns in excel for duplicates

Remark

This method compares cells without case sensitive.

Supposing there are two columns, column B is longer, and column C is shorter as below screenshot shown. Compared with column B, how to find out the missing data in column C?

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

4.1 Compare and find the missing data points (using VLOOKUP or MATCH formula)

If you only want to identify which data is missing after comparing two columns, you can use one of below formulas:

=ISERROR(VLOOKUP(B2,$C$2:$C$10,1,0))

Or

=NOT(ISNUMBER(MATCH(B2,$C$2:$C$10,0)))

 

How to compare columns in excel for duplicates

Press Enter key, then drag auto fill handle over cell D10. Now if the data is in both column B and column C, the formula returns FALSE, if the data is only in column B but misses in column C, the formula returns TRUE.

How to compare columns in excel for duplicates

Remark

Above two formulas compare data without case sensitive.

4.2 Compare two columns and list missing data in below (using INDEX formula)

If you want to list the missing data below the shorter column after comparing two columns, the INDEX array formula can help you.

In the below cell of the shorter column, supposing cell C7, type below formula:

=INDEX($B$2:$B$10,MATCH(TRUE,ISNA(MATCH($B$2:$B$10,$C$2:C6,0)),0))

 

How to compare columns in excel for duplicates

Press Shift + Ctrl + Enter key to get the first missing data, then drag auto fill handle down until it returns the error value #N/A.

How to compare columns in excel for duplicates

Then you can remove the error value, and all missing data has been listed below the shorter column.

Remark

This formula compares cells without case sensitive.

4.3 Compare and find the missing data points and list them in another column (using a handy tool)

If you want to do some follow-up operation on the missing data after comparing two columns, such as listing the missing data in another column or supplementing the missing data below the shorter column, you can try a handy tool-Select Same & Different Cells of Kutools for Excel.

1. Click Kutools > Select > Select Same & Different Cells.

How to compare columns in excel for duplicates

2. In the Select Same & Different Cells dialog, do as below:

1) In Find values in section, choose the longer column that contains the complete list.
In According to section, choose the shorter column which misses some data.

2) Choose Each row option.

3) Choose Different Values option.

How to compare columns in excel for duplicates

3. Click Ok, a dialog pops out to remind you the number of missing data, click OK to close it. Then the missing data has been selected.

How to compare columns in excel for duplicates

Now you can press Ctrl + C keys to copy the selected missing data, and paste them by pressing Ctrl + V keys below the shorter column or another new column as you need.

How to compare columns in excel for duplicates
How to compare columns in excel for duplicates

Remark

Ticking the Case insensitive option in the Select Same & Different Cells dialog will compare two columns with case sensitive.

4.4 Compare two columns and list missing data in below (using VBA)

Here is a macro code that can fill the missing data below the two columns.

1. Open the sheet that you use, press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module to create a new module to place below VBA code into.

How to compare columns in excel for duplicates

VBA: Compare two columns and fill missing data

Sub ExtendOffice_PullUniques() 'UpdatebyKutools20201021 Dim xRg, xRgC1, xRgC2, xFRg1, xFRg2 As Range Dim xIntR, xIntSR, xIntER, xIntSC, xIntEC As Integer Dim xWs As Worksheet On Error Resume Next SRg: Set xRg = Application.InputBox("Select two columns:", "Kutools for Excel", , , , , , 8) If xRg Is Nothing Then Exit Sub If xRg.Columns.Count <> 2 Then MsgBox "Please select two columns as a range" GoTo SRg End If Set xWs = xRg.Worksheet xIntSC = xRg.Column xIntEC = xRg.Columns.Count + xIntSC - 1 xIntSR = xRg.Row xIntER = xRg.Rows.Count + xIntSR - 1 Set xRg = xRg.Columns Set xRgC1 = xWs.Range(xWs.Cells(xIntSR, xIntSC), xWs.Cells(xIntER, xIntSC)) Set xRgC2 = xWs.Range(xWs.Cells(xIntSR, xIntEC), xWs.Cells(xIntER, xIntEC)) xIntR = 1 For Each xFRg In xRgC1 If WorksheetFunction.CountIf(xRgC2, xFRg.Value) = 0 Then xWs.Cells(xIntER, xIntEC).Offset(xIntR) = xFRg xIntR = xIntR + 1 End If Next xIntR = 1 For Each xFRg In xRgC2 If WorksheetFunction.CountIf(xRgC1, xFRg) = 0 Then xWs.Cells(xIntER, xIntSC).Offset(xIntR) = xFRg xIntR = xIntR + 1 End If Next End Sub

How to compare columns in excel for duplicates

3. Then press F5 key to run the code, a dialog pops out for selecting the two comparing columns.

How to compare columns in excel for duplicates

4. Click OK. Now the missing data has been listed below the two columns.

How to compare columns in excel for duplicates

Remark

The code compares cells without case sensitive.

If there are two columns of dates as below screenshot shown, you may want to compare which date is later in the same row.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

5.1 Compare two columns if greater than or less than (using formula)

You can use the simple formula to quickly find whether the date 1 is later than date 2 in each row.

 

How to compare columns in excel for duplicates

Press Enter key to get the first compared result, then drag auto fill handle over to cell C6 to get all results.

How to compare columns in excel for duplicates

Remark

1. In Excel, dates are stored as number series, they are numbers in fact. Therefore, you apply the formula to compare dates directly.

2. If you want to compare if date 1 is earlier than date 2 in each row, change the symbol > to < in the formula.

5.2 Compare two columns if greater than or less than then format (using Conditional Formatting)

If you want to highlight the cells in column Date 1 if are greater than Date 2, you can use the Conditional Formatting feature in Excel.

1. Select the dates in column B (Date1), then click Home > Conditional Formatting > New Rule.

How to compare columns in excel for duplicates

2. In the New Formatting Rule dialog, select Use a formula to determine which cells to format in the Select a Rule Type section, then type formula =$B2>$C2 into the textbox of Format values where this formula is true.

How to compare columns in excel for duplicates

If you want to highlight the cells in column B that are smaller than those in column C, use the formula =$B2<$C2.

3. Click Format button to open the Format Cells dialog, then choose the format type as you need.

How to compare columns in excel for duplicates

4. Click OK > OK. Then the cells in column Date1 which are greater than those in column Date2 have been highlighted.

How to compare columns in excel for duplicates

For example, there are two tables, now you want to compare column B and column E, then find the relative prices from the column C and return them in column F.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

6.1 Pull the exact matching data (using formula or a handy tool)

Here it introduces some helpful formulas and a tool to solve this job.

Formula method

In the cell F2 (the cell you want to place the returned value in), use one of below formulas:

=VLOOKUP(E2,$B$2:$C$8,2,0)

Or

=INDEX($B$2:$C$8,MATCH(E2,$B$2:$B$8,0),2)

 

How to compare columns in excel for duplicates

Press Enter key, and the first value has been found. Then drag auto fill handle down to cell F6, all values have been extracted.

How to compare columns in excel for duplicates

Remark

1. The formulas do not support case sensitive.

2. The number 2 in the formula indicates that you find the matching values in the second column of the table array.

3. If the formulas cannot find the relative value, it returns error value #N/A.

How to compare columns in excel for duplicates

A handy tool method

If you are confused with formulas, you can try the handy tool – Formula Helper of Kutools for Excel, which contains multiple formulas for solving most of problems in Excel. With it, you only need to select the range but not need to remember how the formulas use.

After free installing Kutools for Excel, please do as below:

1. Select the cell F2 (the cell you want to place the return value), and click Kutools > Formula Helper > Lookup & Reference > Look for a value in list.

How to compare columns in excel for duplicates

2. In the Formulas Helper dialog, in right Arguments input section, select the table array range, lookup value and specify which column you want to look for the return value.

Tip: Remember to change the absolute reference in the Lookup_value box to relative, or you only can find the first one value.

How to compare columns in excel for duplicates

3. Click Ok, the first value has been found, then drag auto fill handle down to cell F6.

How to compare columns in excel for duplicates

6.2 Pull the partial matching data (using formula)

If there are some minor difference between the two compared columns as below screenshot shown, the above methods cannot work.

How to compare columns in excel for duplicates

Please choose one of below formulas to solve this job:

=VLOOKUP("*"&E2&"*",$B$2:$C$8,2,0)

Or

=INDEX($B$2:$C$8,MATCH("*"&E2&"*",$B$2:$B$8,0),2)

 

How to compare columns in excel for duplicates

Press Enter key, then drag auto fill handle down to the cell F5, all values have been found.

How to compare columns in excel for duplicates

Remark

1. The formulas do not support case sensitive.

2. The number 2 in the formula indicates that you find the return values in the second column of the table array.

3. If the formulas cannot find the relative value, it returns error value #N/A.

4. * in the formula is a wildcard which is used to indicates any character or strings.

Below data set is an example for comparing and counting matches or difference.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

7.1 Compare two columns and count matches (using SUMPRODUCT formula)

The SUMPRODUCT formula can quickly count the matches in two columns.

=SUMPRODUCT(--(ISNUMBER(MATCH(B2:B8,C2:C8,0))))

 

How to compare columns in excel for duplicates

Press Enter key to get the result.

How to compare columns in excel for duplicates

Remark

The formula counts cells without case sensitive.

7.2 Compare two columns and count matches or differences (using a handy tool)

If you want to count matches or differences between two columns, the handy tool – Select Same & Different Cells.

After free installing Kutools for Excel, please do as below:

1. Click Kutools > Select > Select Same & Different Cells.

How to compare columns in excel for duplicates

2. In the Select Same & Difference Cells dialog, choose the two columns ranges in Find values in and According to sections separately, then choose Each row, and choose Same values or Different Values option as you need.

How to compare columns in excel for duplicates

3. Click Ok. A dialog pops out to tell you how many matching or different cells are selected.

Matching cells

How to compare columns in excel for duplicates

Different cells

How to compare columns in excel for duplicates

Supposing here is a list of data in column B, and you want to count the cells which contain ”Apple” or “Candy” in column D as below screenshot shown:

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

To count if a cell contains one or more values, you can use a formula with wildcards to solve this problem.

=SUM(COUNTIF(B2,"*" & $D$2:$D$3 & "*"))

 

How to compare columns in excel for duplicates

Press Shift + Ctrl + Enter key to get the first checking, then drag autofill handle down to cell F8.

How to compare columns in excel for duplicates

Now if the related cell contains one or more values in column D, the result displays the number greater than 0, if it does not contain any value in the column D, it returns 0.

If you want to count the total number of cells that contain the values in column D, use the formula in the below of cell F8:

How to compare columns in excel for duplicates

Remark

1. Also you can use the formula to count if the cell contains values in another column

=SUMPRODUCT(COUNTIF(B2,"*" &$D$2:$D$3& "*"))

This formula only needs to press Enter key and then drag auto fill handle.

2. In the formulas, * is the wildcard which indicates any character or string.

If you want to delete the differences or matches after comparing two columns as below screenshot shown:

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

You can use the formula to find the difference or matches firstly:

=IF(ISERROR(MATCH(B2,$D$2:$D$8,0)),"Difference","Match")

How to compare columns in excel for duplicates

Press Enter key, and drag auto fill handle down to the cell D8.

How to compare columns in excel for duplicates

Then apply the Filter feature in Excel to filter out the differences or matches value.

Select the formula column, then click Data > Filter.

How to compare columns in excel for duplicates

Then the filter button appears in the column C, click at the filter button to expand the drop-down menu, choose the Difference or Match as you need. Then click OK to finish.

How to compare columns in excel for duplicates

Now only the differences or matches have been filtered out. You can select them and press Delete key to remove them.

How to compare columns in excel for duplicates
How to compare columns in excel for duplicates

Now click Data > Filter again to clear the filter.

How to compare columns in excel for duplicates

Remove the formula column if you do not need it any more.

How to compare columns in excel for duplicates

There are two columns, one contains the original prices, and the other contains the sale prices. Now this part introduces a formula to compare these two columns and then calculate the percentage change between the two columns.

How to compare columns in excel for duplicates

How to compare columns in excel for duplicates
Click to download the sample file

You can use below formula to figure out the percentage change between the two prices in the same row.

 

How to compare columns in excel for duplicates

Press Enter key to get a number, then drag auto fill handle down to cell D7.

How to compare columns in excel for duplicates

Then format the formula result as percentage. Select the results, click Home tab and go to Number group to click Percent Style.

How to compare columns in excel for duplicates

The formula results have been formatted as percentages.

How to compare columns in excel for duplicates

Now you know how to compare two columns after reading above methods. However, in some cases, you may want to compare two ranges (two series with multiple columns) You can use above methods (the formulas or conditional formatting) to compare them column by column, but here introduces a handy tool – Kutools for Excel can solve this job in different cases quickly with formula free.

How to compare columns in excel for duplicates
Click to download the sample file

11.1 Compare two ranges by cell

Here are two ranges needed to be compared by cells, you can use the Select Same & Different Cells utility of Kutools for Excel to handle it.

How to compare columns in excel for duplicates

After free installing Kutools for Excel, please do as below:

1. Click Kutools > Select > Select Same & Different Cells.

How to compare columns in excel for duplicates

2. In the popping Select Same & Different Cells dialog, do as below:

1) In the Find values in section, choose the range that you want to find out the matches or differences after comparing two ranges.

2) In the According to section, choose the other range used to compared range.

3) In Based on section, choose Single cell.

4) Then in the Find section, choose the type of cells that you want to select or highlight.

5) In the Processing of results section, you can highlight the cells by fill background color or the font color, if you do not need to highlight, do not tick the checkboxes.

How to compare columns in excel for duplicates

3. Click Ok. A dialog pops out and reminds how many cells/rows have been selected, click OK to close it. Now the cells that are different with those in the other range have been selected and highlighted.

How to compare columns in excel for duplicates

Highlighting the same values

How to compare columns in excel for duplicates

Remark

If you want to compare two ranges by row, you also can apply the Select Same & Different Cells feature, but in this case, choose the Each row option.

How to compare columns in excel for duplicates
How to compare columns in excel for duplicates

11.2 Compare two ranges if data in the same order

If you want to compare two ranges by row, the Compare Cells feature of Kutools for Excel can help you.

After free installing Kutools for Excel, please do as below:

Supposing, the range F2:H7 is a model, now you want to find if the data in range B2:D7 is in the right order according to the range F2:H7.

How to compare columns in excel for duplicates

1. Click Kutools > Compare Cells.

How to compare columns in excel for duplicates

2. In the Compare Cells dialog, set as below:

1) Choose the two ranges into the Find values in and According to boxes separately.

2) Choose the cell type you want to highlight in the Find section.

3) Choose the highlighting type in the Processing of results section.

How to compare columns in excel for duplicates

3. Click Ok. A dialog pops out and reminds how many cells have been selected, click OK to close it. Now the cells that are different with those in the other range have been selected and highlighted.

How to compare columns in excel for duplicates