How to Find Duplicates in Two Lists: A Step-by-Step Guide to Comparing Spreadsheets in Google Sheets
Ever found yourself with two lengthy lists in Google Sheets, wondering if there are any duplicates hiding within? Manually cross-referencing can be time-consuming and prone to human error. Thankfully, Google Sheets offers several tools to efficiently compare two lists and identify duplicates. Let's explore three methods to achieve this.
Before we dive in, ensure both of your lists are in separate columns (ideally A and B) and there are no blank cells in the data range you want to compare.
Using the 'Remove Duplicates' Feature
This method is simple and effective for finding and removing duplicates from one list against another. However, it won't show you what the duplicates are; it will only display the count.
Here's how to use it:
Using the Remove Duplicates Ribbon
1. Select the range of cells containing the first list (e.g., Column A).
2. Click on 'Data' in the menu, then 'Remove duplicates'. A dialog box will appear.
3. Ensure only the column containing the first list is checked. Click 'Remove duplicates'. Google Sheets will count and remove duplicates from the second list (Column B) against the first.
Using the 'Remove Duplicates' Script
If you're comfortable with scripts, you can automate this process. Here's a simple script to remove duplicates:
Code.gs:
function removeDuplicates() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange("A2:B"); // adjust the range as needed
range.getValues().filter(function(row){
return !sheet.getRange("A2:A").getValues().filter(function(prevRow){
return row[0] === prevRow[0]; // column A comparison
}).length;
}).forEach(function(row){
sheet.appendRow(row); // append non-duplicates to the end of the sheet
});
}
Adjust the range as needed, then run the script with a click. The results will be appended to the end of the sheet.
Using Conditional Formatting to Highlight Duplicates
If you want to visually identify duplicates, use conditional formatting. This method allows you to color-code or highlight duplicates in the second list based on their presence in the first.
Here's how to set it up:
Using Custom Formula for Conditional Formatting
1. Select the range of cells containing the second list (e.g., Column B).
2. Click on 'Format' in the menu, then 'Conditional formatting'.
3. Under 'Format cells if...', select 'Custom formula is'.
4. Enter the following formula: `=COUNTIF($A:$A, B1)>1` (adjust column references as needed).
5. Choose your desired formatting (e.g., fill color), then click 'Done'.
Now, any cells in Column B that contain duplicates will be highlighted according to your selected format.
Using a VLOOKUP to List Duplicates
If you want to create a new list of just the duplicates, use a VLOOKUP. This method will show you exactly which values are duplicates and in which rows they occur.
Here's how to do it:
Using VLOOKUP to List Duplicates
1. In a new column (e.g., Column C), enter the following formula: `=IF(COUNTIF($A:$A,B1)<2,, "Duplicate")`.
2. Drag this formula down to the end of your data range.
Any cells in Column B that contain duplicates will now display " Duplicate" in Column C. Adjust column references if needed.
avisualizing and managing duplicates in Google Sheets can significantly streamline your workflow and reduce manual effort. Try out these methods and watch your productivity soar!