VBA Remove Duplicates in Column in Excel

Home/VBA/VBA Remove Duplicates in Column in Excel

VBA code to Remove Duplicates in a Column in Excel Example Macros to delete duplicate records in columns of worksheet in MS Excel 2003, 2007, 2010, 2013. Example to show you how to delete duplicate records in Columns from Excel Worksheet.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA code to Remove Duplicates in a Column

Here is the Example VBA syntax and Example VBA Macro code to Remove Duplicates in a Column in excel worksheets. This will help you to know how to delete duplicate records in columns from Excel workbook using VBA.

VBA Remove Duplicates in a Column: Syntax

Following is the VBA Syntax and sample VBA macro command to delete duplicate in a column from worksheet using VBA. We are using the RemoveDuplicates method of the Columns object of worksheet.

Columns(ColumnNumber).RemoveDuplicates Columns:=Array(1) 

Here Columns(ColumnNumber).RemoveDuplicates command tells excel to remove the duplicated based on the required Column Number. Columns:=Array(1) will help us to mention the column number to check for the duplicates if there are more than one columns.

VBA Remove Duplicates in a Column: Examples

The following Excel VBA macro code is to delete duplicates in columns from the worksheet. This VBA macro will delete the records based on the column 2.

Sub sbRemoveDuplicates()
Columns(2).RemoveDuplicates Columns:=Array(1)
End Sub 

Instructions to run the VBA Macro code to delete duplicates in a Column in Excel


Please follow the below steps to execute the VBA code to delete duplicate Rows in Excel.

  • Step 1: Open any Excel workbook
  • Step 2: Press Alt+F11 – This will open the VBA Editor
  • Step 3: Insert a code module from then insert menu
  • Step 4: Copy the above code and paste in the code module which have inserted in the above step
  • Step 5: Enter some data in the second column of worksheet. Also enter some duplicate data for testing purpose.
  • Step 6: Now press F5 to execute the code

Now you can observe that the duplicate data is removed from the Column 2 which we have mentioned in the above example code.

Explained VBA Code to Delete Active Column

Starting Macro program and sub procedure to write VBA code to delete duplicate records in a column of Excel Worksheet.

Sub sbRemove_Duplicates_in_columns()
‘Here Columns refer entire column in the worksheet
‘RemoveDuplicate method is for removing the duplicate records
‘And the Columns parameter is to specify the based on which column to remove duplicate records.
Columns(2).RemoveDuplicates Columns:=Array(1)
End Sub
End statement to end the VBA code to remove duplicate records in a column

LIMITED TIME OFFER
By |January 19th, 2015|VBA|3 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

3 Comments

  1. Jason June 30, 2015 at 9:54 PM - Reply

    Is it possible to copy the duplicates instead of removing them? What I’m trying to figure out is a way to find duplicates and copy them into a new worksheet. See example below:

    ActiveSheet.Range(“$A$1:$D$8”).CopyDuplicates Columns:=Array(1, 2), Header _
    :=xlYes

    Thanks!

    • PNRao July 1, 2015 at 12:39 AM - Reply

      Hi Jason,
      We do not have the built-in function to copy the duplicates, however we can write a userdefined function to do this. or we can use countif and advanced filter to get the duplicates.

      Thanks-PNRao!

  2. Venkat March 13, 2016 at 8:08 PM - Reply

    Dear Sir, To remove duplicate I found a code as below

    Range(“a1:a10”)).select
    Selection.removeduplicates (1) Why is this (1) used when already the range has been specified to check for duplicate..
    Regards

    Venkat

Leave A Comment


Related pages


column method worksheetsadodb.connection openexcel rgb formulahow to do an hlookupexcel for beginners tutorialexcel vlookup naexcel macros 2007how to find password of protected sheet in excelsave workbook in excelvba cutnested if condition in excelword to excel macrovba msg boxchart samples from excelexcel vba insert rowcell color in vbavba excel close file3d graphing excelcreate vbacheck for duplicates excelcopy tabs in excelsql test questions and answers pdfexcel vba ebookenable macros vbaquery sql server from excelexcel tab shortcutuserform excel 2007removing duplicate entries in excelvba delayhyperlink codingdelete duplicate excelcopy vbashortcut key for next sheet in exceltick boxes in excelsample excel macro codeexcel 2007 remove duplicatesexcel consolidate multiple workbookshow to use a pivot table in excel 2010assign macro to data validation listcountifs excel formulaapplication.worksheetfunctionvb messageboxunhide sheets in excel 2007vlookup syntax in excelactivesheet.listobjects.addexcel worksheet columnsunprotect cells in exceloperators and operandsexcel 2003 remove duplicatesexcel vba copy sheet to endsumif excel vbavba hyperlink addressvba excel worksheetscsv converter to exceljob costing template freeinsert a check box in excelhow to unhide columns on excelbreak statement in vbaremove blank columns in excelvba close workbookvba programmerquotes in excel formulahlookup vbainsert comment in excelinfosys interview questions and answers for freshersexcel duplicate countexcel vba class module examplevba color chartusing offset function in excelprogrammer analyst interview questionsvba word userformcreating excel dashboardssample vb programs for beginnerssql developer interview questions and answers pdfplsql for dummieslearning vba codesheets copy vba