Excel Compare Two Columns & Report Differences
Learn how to compare multiple columns in Excel with huge volume of data.- Find duplicate entry in 2 columns using Conditional Formatting
- Compare for duplicates using countif.
- Compare Two columns & find duplicates using Excel VBA
Compare & Highlight Matching Duplicate Records
Assume the data to compare are in Columns A & B. Just to see the duplicate entries with colour difference follow this method.- Select all columns that has data.
- Click Home in Excel menu.
- Choose “Conditional Formatting” -> “Highlight Cells Rules” -> “Duplicate Values”
- Choose the font colour & background to highlight.
- Click Ok. Values with repetition will be highlighted.
Find Duplicate Entries in Two Columns with Excel Formula
It can be done with a Lookup or Countif Formula. Countif is simpler compared to a lookup formula. How to compare two columns with Countif? i.e., Get value from column B, compare it with Column A & find whether any value is repeated.- Assuming Column A & B are to be compared.
- Enter this formula in cell C1.
- Formula ‘=countif(“$A:$A”,$B1)’
- Copy paste this formula in Column C till end of data rows.
- Unique values will have count as ‘0’.
- Repeating or duplicate entries will have count greater than ‘0’.
Compare & Find duplicate entries in Two columns with Excel VBA Macro
In Excel VBA, this can be done by plain comparison of each cell with two for loops, which is very efficient for low volume of data. In case, if you have huge volume of data, then the above loop will keep on execute for long hours or days to complete. There are also possible chances that Excel application will hang in middle of execution & result in data loss. To compare a huge volume of data in your Excel sheet, use this method to find duplicate values and report the differences.Public Sub Compare_Two_Columns_Highlight_Duplicates()
Dim iRow As Double, oRow As Double, wsI As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim iTotRecsA As Double, iTotRecsB As Double
'Iniate Variables
iRow = 1
Set wsI = ThisWorkbook.Sheets("InputSheet")
'Get Total number of records in Column
iTotRecsA = wsI.Range("A" & Rows.Count).End(xlUp).Row
iTotRecsB = wsI.Range("B" & Rows.Count).End(xlUp).Row
'Loop thru each data in Column A
While wsI.Cells(iRow, 1) <> ""
'Compare Column A value with Column B
Val1 = wsI.Cells(iRow, 1)
wsI.Cells(iRow, 1).Interior.Color = vbWhite
If Application.WorksheetFunction.CountIf(wsI.Range("B1:B" & iTotRecsB), Val1) > 0 Then
'Highlight when Count is Greater than 0
wsI.Cells(iRow, 1).Interior.Color = vbYellow
End If
'Process next row data
iRow = iRow + 1
Wend
MsgBox " Data Comparison Completed"
End Sub
This code will not take much time. It executes much faster than a normal comparison.
Much better than this.
In case if you don’t want to compare all these columns data & in a hurry to remove all duplicate entries. Then Excel has built in option Menu -> Data -> “Remove duplicates’
Just select all the cells with data and click this option. It will remove all duplicate entries in seconds.
Duplicates are fine. But how to find unique values?
Well. It is easy.
Just use the same VBA code or formula method with countif. Or, you can follow this link to find a technique that uses “Advanced Filter” option within Excel itself.