Removing Everything Except Duplicates

Written by Allen Wyatt (last updated December 14, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365


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, 2021, and Excel in Microsoft 365.

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

Getting a Count of Unique Names

When you've got a column full of names, you may want to get a count of how many of those names are unique. You can make ...

Discover More

Strange ATAN Results

You may use Excel's trigonometric functions to do some quick calculations, and suddenly notice that the results in your ...

Discover More

Unknown Non-Printing Characters

When you paste information into Word from the internet, you may get more than just the plain text you hoped for. This tip ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Counting Asterisks

For some operations and functions, Excel allows you to use wild card characters. One such character is an asterisk. What ...

Discover More

Where Is that Text?

Looking for a formula that can return the address of a cell containing a text string? Look no further; the solution is in ...

Discover More

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
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 two more than 9?

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.