How to Remove Duplicate Names in Excel (6 Simple Methods)

The following dataset contains the names of some salesmen, their state addresses, sales amounts in dollars, and target achievements.

Dataset content


Method 1 –  Using the Remove Duplicates Feature 

Selecting Remove Duplicate Feature

  • Select any cell from the dataset.
  • Select Data >> Remove Duplicates from the Data Tools

Choosing Remove Duplicate parameter

  • The Remove Duplicates dialog box will pop up.
  • Check a column name on which you will operate the Remove Duplicates. Make sure to select My data has headers.
  • Click OK.

Following rows removed containing duplicate names

  • All the duplicate names are removed. Only the unique names will prevail in the sheet.

Checking more column contents to remove all duplicate values in a row

If you want to remove duplicate values based on the whole contents of the rows, you need to check all the columns. Here, the 6th and 12th rows of the sheet are exactly the same. The same can be said for the 8th and 11th rows.

The following picture shows the unique rows only.

Only unique rows prevailed after removing duplicate rows

Note: The command may remove some necessary data. You should keep a copy of your original data in your Excel workbook.

Read More: Remove Duplicate Rows Except for 1st Occurrence in Excel 


Method 2 –  Using an Advanced Filter

Steps:

  • Select the Names column.
  • Go to Data >> Advanced Filter from the Sort & Filter
  • Check Unique records only on the Advanced Filter dialog box and click OK.

You will see all the duplicate names removed from the data table.

Here, we removed duplicate data based on Names. You can also do the same for the States column too. Hopefully, the following video will be helpful on this matter.

We removed the duplicate ‘States’ data similarly.

Note: We cannot get summarized data for each unique entry using the Advanced Filter feature.

Read More: How to Remove Both Duplicates in Excel 


Method 3 –  Using a Pivot Table 

Steps:

  • Select the whole data table.
  • Select Insert >> PivotTable.
  • In the PivotTable dialog box, choose the sheet where you want to keep the PivotTable. We selected a New Worksheet for our PivotTable.
  • Click OK.

The PivotTable will appear in a new sheet. Using this PivotTable, we can make a data table without Duplicate Names. Watch the video below to understand this idea.

Advantage: The main advantage of using PivotTable is getting the summarized data for each entry. We got the unique names that appeared first in the data table when we used Advanced Filter.

Read More: How to Remove Duplicates and Keep the First Value in Excel


Method 4 –  Using a Formula

Steps:

4.1. Dynamically Remove Duplicate Names Using UNIQUE Function

  • To make the procedure dynamic, convert the dataset to a table.
  • Select the whole data range and press Ctrl + T
  • Check that My Table has headers, and click OK on the dialog box.
  • Select any cell where you want to keep the unique names and type the formula below.
=UNIQUE(B4:E14)

The formula will return the unique rows only.

Formatting the returned values by UNIQUE function

The returned range does not have any formatting. So format it according to your convenience.Updating unique data dynamically

Advantage: The procedure is dynamic. Once you insert a new name, it will automatically update the range obtained using the UNIQUE function. In the above image, we added unique data in the 15th row and duplicate data in the 16th row. You can see the unique data in the formula’s output range.


4.2. Remove Duplicate Names Using COUNTIF Function

  • In the helper column, enter the formula below and use the Fill Handle feature to AutoFill the lower cells.
=COUNTIF($B$5:B5,B5)
  • Watch the video below on extracting the unique names by applying a Filter in the data table.

The following steps were covered in the video.

  • Select any cell of the data table.
  • Press Ctrl + Shift + L to apply Filter on it.
  • Select the drop-down icon beside the Helper column and uncheck 2 and 3.
  • Click OK.

You will see only the unique names after this operation.

However, the Filter command doesn’t remove the duplicate names; it just hides them. To permanently remove the duplicate names, follow the video below.

In the video, the following tasks were done.

  • Select the drop-down icon beside the Helper column. Unchecked 1, and click OK.
  • The duplicate names will be filtered.
  • Delete these rows with duplicate names and press Ctrl + Shift + L.

Now, you will see the unique names only.


Method 5 –  Using the Power Query Editor

Steps:

  • To open the Power Query Editor, convert your dataset to a table.
  • Select the table and go to Data >> From Table/Range.

Data table in the Power Query Editor

In the Power Query window, you will see the data table appear. It is accessible to various features to analyze.

The following steps were shown in the video.

  • Click on the first column name (Names).
  • Hold the Shift key and click on the last column name (Target Acquired).
  • Select Remove Rows >> Remove Duplicates.
  • You will see only unique data in the Power Query Editor.

Removing Duplicate Rows using command from query drop down options

You can also remove all the Duplicate Names and data in a row from the drop down options shown in the above picture.

Loading data in a new sheet

Select the Close & Load command from the Power Query ribbon. This will automatically import the data table to a new sheet.

Data table without duplicate data appeared in new sheet

If you want to keep the unique names only and remove other duplicate names, right-click on the heading of the Names column and select Remove Duplicates.

Removing Duplicate Names using Context Menu in Power Query Editor

You will see the changed query with the unique names only. Using the Close & Load command, you can load it in a new sheet.

Data table in the Power Query Editor with unique names

Advantages: Using the Power Query Editor to remove duplicate names allows us to update the table dynamically. Say you add one duplicate and one unique data point in the table, as shown in the following image.

Inserting additional unique and duplicate data

  • To update the data table, refresh it. Please follow the video below to understand this topic.

We covered the following steps in the video.

  • Place the cursor anywhere on the table extracted from the Power Query Editor.
  • Right-click and select the Refresh command from the Context Menu.

Your table from the Power Query Editor can be updated with the non-duplicate values.


Method 6 – Using VBA

Steps:

6.1. Removing Duplicates from Fixed Cell Range

  •  To open the VBA window, press Alt + F11.

Opening the VBA module

  • The VBA window will appear.
  • Now, select Insert >> Module. This command will open a VBA module.

VBA code to remove duplicate from fixed range

Sub RemoveFromFixedRange()
Range("B4:E14").RemoveDuplicates Columns:=1
End Sub
  • Go back to your sheet and select Developer >> Macro or press Alt + F8.
  • Select the Macro named RemoveFromFixedRange and click OK.
  • Watch the video below to better understand this matter.

After running the Macro, you will see only duplicate names with their first corresponding rows.


6.2. Removing Duplicates from Selected Cell Range

  • Enter the code below into a new Module:
Sub RemoveDuplicatesSelectedRange()
Dim mn_input_range As Range
Set mn_input_range = Selection
mn_input_range.RemoveDuplicates Columns:=1, Header:=xlYes
End Sub

Code Breakdown

  • First, a sub-procedure named RemoveDuplicatesSelectedRange() is initiated.
  • Next, we declared a variable mn_input_range as Range.
  • Following that, we set the input range variable to Selection.
  • After that, we used the RemoveDuplicates Method to remove the duplicates from the selected range.
  • Run the code.

Follow the video below to see how to remove duplicates from a selected range.

If you want to keep the data in the first 4 rows and remove the duplicate names from the 5th row of the dataset.

  • Select the range B9:E14.
  • Run the Macro and remove the duplicate names from the 5th row of our dataset.

We can also introduce a Button to make our task easier. Creating a button to assign macro

  • Select Developer >> Insert >> Button from the Form Controls
  • Create the button by dragging the mouse and give it a name.

Selecting Assign Macro option from Context Menu

  • Right-click on the button and select Assign Macro from the Context Menu. You can also assign a Macro before giving the button name.

Macro Assigned to the button

  • A dialog box will pop up.
  • Assign the macro you want to run with the button click and click OK.

Watch the following video to learn how to run the Macro to remove duplicate names using a button click.


How to Highlight Duplicate Names in Excel

If you want to highlight duplicate names, go through the following steps rather than removing them.

Applying Conditional Formatting feature

  • Select the column or range where your duplicate names will be highlighted.
  • Select Conditional Formatting >> New Rule.

Assigning formula to the Formatting Rule

  • A dialog box will pop up. Select ‘Use a formula to determine which cells to format’ and copy the formula below to set the rule.

=COUNTIF($B$5:B5,B5)>1

Selecting Fill color to format cells

  • Select a fill color that will highlight the duplicate names and click OK.

Preview of Formatting Rule

A preview will appear showing how the formatted cells will look like. Just click OK again.

Duplicate values are highlighted

The duplicate names will be highlighted in the data table. Thus, you can apply Conditional Formatting to highlight duplicate values.


How to Keep Duplicate Rows in Excel

Open the Power Query Editor with the data table. Method 5 shows how to open a Power Query Editor. Follow the video below to see how to keep duplicate rows in the Power Query Editor.

We showed the following steps in the video.

  • Select the first column heading, hold the Shift key, and select the last column heading.
  • Select Home >> Keep Rows >> Keep Duplicates.
  • You will see the Duplicate Rows.

Loading table with duplicate data only

Following the image above,

  • select the Close & Load command.

Table with Duplicate Names

You will see a table with the duplicate names in a new sheet.


Download the Practice Workbook


Related Articles


<< Go Back to Remove Duplicates in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mahbubur Rahman
Mahbubur Rahman

MAHBUBUR RAHMAN is a leather engineer with a talent for Excel and a passion for VBA programming. To him, programming is like a time-saving wizard, making data manipulation, file handling, and internet interactions a breeze. His skill set extends to SPSS, STATA, Deep Neural Networks, and Machine Learning. Holding a B.Sc in Leather Engineering from Khulna University of Engineering & Technology, he's shifted to become a content developer. In this role, he crafts technical content centred around Excel... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo