Delete Duplicate Values in All Versions of Excel

Add to Favorites
Author: | Edits: don

How to delete duplicate values from a data set in all versions of Excel. This includes Excel 2003 and earlier and also Excel 2007 and later.

For Excel 2007 and later, we can use a simple feature within the program, but for Excel 2003 and earlier, we must use a macro, which is provided below.

Sections:

Remove Duplicates in Excel 2007 and Later Versions

Remove Duplicates in Excel 2003 and Earlier Versions

Notes

Remove Duplicates in Excel 2007 and Later Versions

  1. Select a cell within the data set that contains the duplicates:
    46c6394e920b3f5b4db0d1372a9e4276.png
  2. Go to the Data tab and then click Remove Duplicates:
    a6a08bc6ddc1a6a19a8ffdac1b2cccb4.png
  3. You should now see a small window open.
    (Also, Excel should have selected the entire data set, in our example, A1:B6; if it did not select the correct data set, then you need to hit the Cancel button and select the entire data set yourself before clicking the Remove Duplicates button.)
    In the small window, you need to select which column you want to check for duplicates.  You can select one column to check or multiple columns.
    If there are headers or titles for your data and those were also selected by Excel, then click the checkbox next to where it says My data has headers.
    52656e996fb3f971fcc046acf6d0a982.png
    In this example, my data does not have headers and I only want to search Column A for duplicates, so I uncheck Column B and then hit OK.
    eab992ae667abd393b6bf7d442f9ff3f.png
  4. Excel will remove the duplicates and you will see a window telling you how many duplicates were removed.
    072ecbf385c090f9709c1584f299bc66.png
  5. Here is the final result:
    4cc99716cce79b5f3a951e22049d705c.png

Notice that Excel removed the entire row of data and not just the data in Column A.

If you had selected Column A and Column B in Step 3, then no value would have been removed.  This is because, Excel looks at all the values in all the selected columns to see if there are duplicates across them instead of individually in each column.  That is important if you want to perform more complex duplicate removal in Excel.

If you made an error, hit Ctrl + Z on the keyboard to undo the duplicate removal and start over.

Remove Duplicates in Excel 2003 and Earlier Versions

To remove duplicate values from Excel 2003 and earlier versions, we need to use a Macro.

Here are the steps to install and use the macro:

  1. When in Excel, hit Alt + F11 to go to the VBA Editor window.
    af1c90450830464dd645244f8aa01919.png
  2. Go to Insert > Module
    06b33b865792cae573fa201d23b135a1.jpg
  3. You should now see a small window open and that is where we will input the macro:
    143ef6ae89f161d303b40ae69fb9225a.jpg
  4. In that window, copy and paste this macro:
    Public Sub DeleteDuplicateRows()
    ' This macro will delete all duplicate rows which reside under
    ' the first occurrence of the row.
    '
    'Use the macro by selecting a column to check for duplicates
    'and then run the macro and all duplicates will be deleted, leaving
    'the first occurrence only.
    
    Dim R As Long
    Dim N As Long
    Dim V As Variant
    Dim Rng As Range
    
    On Error GoTo EndMacro
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    Set Rng = Application.Intersect(ActiveSheet.UsedRange, _
                        ActiveSheet.Columns(ActiveCell.Column))
    
    Application.StatusBar = "Processing Row: " & Format(Rng.Row, "#,##0")
    
    N = 0
    
    For R = Rng.Rows.Count To 2 Step -1
    
        If R Mod 500 = 0 Then
        
            Application.StatusBar = "Processing Row: " & Format(R, "#,##0")
        
        End If
        
        V = Rng.Cells(R, 1).Value
        
        If V = vbNullString Then
        
            If Application.WorksheetFunction.CountIf(Rng.Columns(1), vbNullString) > 1 Then
        
                Rng.Rows(R).EntireRow.Delete
        
                N = N + 1
        
            End If
        
        Else
        
            If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
        
                Rng.Rows(R).EntireRow.Delete
        
                N = N + 1
        
            End If
        
        End If
    
    Next R
    
    EndMacro:
    
    Application.StatusBar = False
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    MsgBox "Duplicate Rows Deleted: " & CStr(N)
    
    End Sub
    
    
  5. It should now look something like this:
    aa2c5c5194d57c4582ea8dfc03b0078e.jpg
    (If there was a problem performing the copy/paste from this site, make sure the single quotation marks in front of the green text are indeed basic normal single quotation marks; you can do this by deleting and retyping them in the VBA Editor window here. Or, just download the sample file attached to this tutorial and copy the macro from there.)
  6. Hit Alt + F11 to go back to the Excel window and select a cell within the column of duplicate values that you would like to remove:
    d0b2ae56dfdd1501646bae3310bd8d79.png
  7. Hit Alt + F8 to see the macro.
    ca666b8d85185a16598c40b4e85565ee.png
  8. Select the one called DeleteDuplicateRows and then hit the Run button.  Once you do that a small window will appear telling you how many duplicates were removed:
    22114079c9bebda1bb5cb35f1373eb9a.png
  9. Hit OK and you're done!
    2a1dcee644ee9945161ad0a0dc097813.png

This method works pretty much the same, though is not as robust, as the Remove Duplicates feature for Excel 2007 and later.

You cannot "undo" this action by hitting Ctrl + Z or anything else, so, be aware that whatever the macro removes is irreversible.  Have a backup of the original data made before running any macro in case an error happens.

If you want to keep this macro in your workbook, make sure to save the workbook in a format compatible with macros; when you go to save the file, Excel will tell you if there is an issue, and, if you don't see a warning, it should save just fine in the spreadsheet.

Follow this tutorial to run the macro when you click a button in the worksheet.

Notes

If you are in Excel 2007 and later, use the built-in method to remove duplicates since it is so much easier compared to having to install a macro and since you can undo the action if you make a mistake.

If you use the macro, you cannot undo any changes it makes to the worksheet; always make a backup of your data before running a macro.

Be careful removing duplicates on spreadsheets with a lot of data spread-out throughout the worksheet because it might remove data to the right or left of your current data set.  The best thing to do is to have a separate worksheet that only contains the data that you want to check for duplicates.  This way, you are certain to not mess with any other data.

Make sure to download the accompanying spreadsheet for this tutorial.  It contains the macro listed here and some sample data for you to try everything out.


Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Simple Excel Function to Combine Values in All Versions of Excel - UDF
: Excel function that combines values from multiple cells or inputs using a delimiter - work...
Prevent Duplicate Values in Excel
Tutorial: I show you how to prevent duplicate values being entered into Excel using Data Validation...
Easily Compare Duplicate Values in Excel
Tutorial: Here, I'll show you a simple technique to quickly and easily compare large lists of duplic...
Highlight Duplicate Values in Excel
Tutorial: How to highlight duplicate values in a list. Also, how to arrange those values next to ea...
SUMIF - Sum Values Based on Criteria in Excel
Tutorial: The SUMIF function allows you to sum values based on a single criteria. This function wor...
Delete Duplicate Rows
Macro: This macro will delete rows that appear twice in a list or worksheet. If two cells are...
Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course