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

Alphabetizing Worksheet Tabs

As yo get more and more worksheets into a workbook, you'll find yourself moving them around into different sequences. You ...

Discover More

Converting to Octal

If you need to do some work in the base-8 numbering system (octal), you'll love two worksheet functions provided by Excel ...

Discover More

Deciphering a Coded Date

It is no secret that Excel allows you to work with dates in your worksheets. Getting your information into a format that ...

Discover More

Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!

More ExcelTips (ribbon)

Counting Employees in Classes

Excel is very good at counting things, even when those things need to meet specific criteria. This tip shows how you can ...

Discover More

Last Non-Zero Value in a Row

If you have a lot of values in a single row, you might want to pull the last non-zero value from that row. There are a ...

Discover More

Generating Random Door Access Codes

People often use Excel to maintain lists of information that they need to track. This tip shows several ways you can ...

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 6 - 1?

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.