Written by Allen Wyatt (last updated December 14, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
Barry knows he can use the Remove Duplicates tool on the Data tab of the ribbon to remove duplicate rows. He wonders, though, if there is a way to do the opposite, to remove any rows that are not duplicated and leave only the duplicate rows.
There isn't any built-in Excel tool or function that will give the desired results, but there is an easy way to accomplish the task using a helper column. For the sake of simplicity, let's say that you determine whether a row is a duplicate or not based entirely on the contents of column A. In an unused cell, you could add the following formula to row 2 of whatever column you want to use as the helper:
=COUNTIF(A:A,A2)
The formula returns a count of how many times the value in A2 occurs in column A. If the value returned is 1, then you know the row is not a duplicate; it is unique. Copy the formula down for as many rows as necessary, then you can filter based on the helper column. You can filter to show only the rows that have 1s and delete them. Or, you could filter to show only rows that are greater than 1. These are the duplicates, and you could copy them to a different location.
If you need more than a single row to determine what is a duplicate or not, then you can use two helper columns. Let's say that the determining columns are A, B, C, and D. Further, let's assume that you are using column H as your first helper column. In that case, you would enter the following into cell H2:
=A2&B2&C2&D2
This concatenates the first four cells in the row. If you are using Excel 2019, Excel 2021, or the version of Excel in Microsoft 365, you could use the following formula, instead:
=CONCAT(A2:D2)
Copy this down as many rows as needed, and then enter this into cell H2:
=COUNTIF(H:H,H2)
Once you copy this down for all the rows, you again end up with an indication of how many rows are duplicated, if the result is greater than 1. And, again, you can delete filtered rows or copy filtered rows, as necessary.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13945) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
If you need to randomly match up items in two lists, there are a variety of techniques you can use. Here are a couple of ...
Discover MoreIf you have a series of consecutive numbers in a column, you may want to know if it really is consecutive. (In other ...
Discover MoreNeed to count the number of cells in a range that are not blank? You can use the COUNTA function of a more complex ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-12-16 12:22:24
Gary Lundblad
Great tip Allen! Another option, because who doesn't love multiple options, would be to use a conditional formatting rule to highlight duplicates, and then filter that column by the color used in the conditional formatting rule, but you'd want to choose those without the fill color in your filter, or instead of specifying "duplicate" values in your conditional formatting rule, change it to "unique." Then filter by the color you chose in the rule.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments