Microsoft optimize

How to find duplicates in Excel

You'll need more than one trick up your sleeve to find duplicates in Excel.

In the duplicate world, definition means everything. That's because a duplicate is subjective to the context of its related data. Duplicates can occur within a single column, across multiple columns, or complete records. There's no one feature or technique that will find duplicates in every case.

To find duplicate records, use Excel's easy-to-use Filter feature as follows:

  1. Select any cell inside the recordset.
  2. From the Data menu, choose Filter and then select Advanced Filter to open the Advanced Filter dialog box.
  3. Select Copy To Another Location in the Action section.
  4. Enter a copy range in the Copy To control.
  5. Check Unique Records Only and click OK.

january2009blog6fig1.jpg

Excel will copy a filtered list of unique records to the range you specified in Copy To. At this point, you can replace the original recordset with the filtered list (the copied list) if you want to delete the duplicates.

january2009blog6fig2.jpg

Finding duplicates in a single column or across multiple columns is a bit more difficult. Use conditional formatting to highlight duplicates in a single column as follows:

  1. Using the example worksheet, select cell A2. When applying this to your own worksheet, select the first data cell in the list (column).
  2. Choose Conditional Formatting from the Format menu.
  3. Choose Formula Is from the first control's drop-down list.
  4. In the formula control, enter =COUNTIF(A:A,A2)>1.
  5. Click the Format button and specify the appropriate format. For instance, click the Font tab and choose Red from the Color control and click OK. At this point, the Conditional Formatting dialog box should resemble the following figure:

january2009blog6fig3.jpg

  1. Click OK to return to the worksheet.
  2. With cell A2 still selected, click Format Painter.
  3. Select the remaining cells in the list (cells A3:A5 in the example worksheet).

january2009blog6fig4.jpg

The conditional format will highlight any value in column A that's repeated. If you want Excel to highlight only the copies, leaving the first occurrence of the value unaltered, enter the formula =COUNTIF($A$2:$A2, A2)>1 in step 4.

The conditional format works great for a single column. To find duplicates across multiple columns, use two expressions: One to concatenate the columns you're comparing; a second to count the duplicates. For example, if you wanted to find duplicates of both first and last names in the example worksheet, you'd enter the following formula in cell D2 to concatenate the first and last name values:

=A2&B2

You could insert a space character between the two names if you liked, but it isn't necessary. Copy the formula to accommodate the remaining list items.

january2009blog6fig5.jpg

Next, in cell E2 enter the following formula and copy it to accommodate the remaining list:

=IF(COUNTIF(D$2:D$7,D2)>1,"Duplicated","")

january2009blog6fig6.jpg

Notice that the worksheet has a new record (row 6). This record duplicates the first name, Susan, but not the last name. The conditional format highlights the first name because it's a duplicate in column A. However, the formula in column E doesn't identify the combined values across columns A and B as a duplicate because the first and last names together aren't duplicated.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

0 comments