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
Out of these three methods, the third one is very faster. This methods can be used to compare huge column of data within less time.
Are you not excited to get such a easy solution?. Read more…
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.
No, Excel will compare the data in selected data range and highlight all the duplicate entries.
The problem with this method, is that it highlights all the differences with same colour. Also we cannot select only the duplicate entries.
Is that it? No. we have few advanced options too.
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’.
Now we have the comparison data in Column C for B->A verification. The data in Column C can be filtered for unique or duplicate entries.
If this same process has to be done for A->B comparison, then the formula should be reversed as ‘=countif(“$B:$B,$A1)’
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.
123456789101112131415161718192021222324252627282930Public Sub Compare_Two_Columns_Highlight_Duplicates()Dim iRow As Double, oRow As Double, wsI As WorksheetDim Val1 As Variant, Val2 As VariantDim iTotRecsA As Double, iTotRecsB As Double'Iniate VariablesiRow = 1Set wsI = ThisWorkbook.Sheets("InputSheet")'Get Total number of records in ColumniTotRecsA = wsI.Range("A" & Rows.Count).End(xlUp).RowiTotRecsB = wsI.Range("B" & Rows.Count).End(xlUp).Row'Loop thru each data in Column AWhile wsI.Cells(iRow, 1) <> ""'Compare Column A value with Column BVal1 = wsI.Cells(iRow, 1)wsI.Cells(iRow, 1).Interior.Color = vbWhiteIf Application.WorksheetFunction.CountIf(wsI.Range("B1:B" & iTotRecsB), Val1) > 0 Then'Highlight when Count is Greater than 0wsI.Cells(iRow, 1).Interior.Color = vbYellowEnd If'Process next row dataiRow = iRow + 1WendMsgBox " 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.
Previous Post: Excel Count Cells By Color – Using VBA ColorIndex – CountByColor
Compare Two Columns Excel – Highlight Match – Bulk Data Duplicates
Top5 Trending Posts