Removing Everything Except Duplicates

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


1

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing a Shape

Got a drawing shape you previously added to a document, but you now want to change to a different shape? You can change ...

Discover More

Getting the Expected Space Before a Heading

If your heading styles are designed to add extra space before the heading, you may be surprised when that extra space is ...

Discover More

Copying and Pasting Field Codes

Want to copy a field code and paste it in some other Windows program? This can be trickier than it sounds. Here's the ...

Discover More

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!

More ExcelTips (ribbon)

Randomly Assigning Names to Items

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 More

Identifying Missing Numbers in a Consecutive Series

If you have a series of consecutive numbers in a column, you may want to know if it really is consecutive. (In other ...

Discover More

Counting Non-Blank Cells

Need to count the number of cells in a range that are not blank? You can use the COUNTA function of a more complex ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 5?

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.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.