VBA Remove Duplicates in a Range in Excel

Home/VBA/VBA Remove Duplicates in a Range in Excel

VBA code to Remove Duplicates in a Range in Excel Example Macros to delete duplicate records in Range of worksheet in MS Excel 2003, 2007, 2010, 2013. Example to show you how to delete duplicate records in Range 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 Range

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

VBA Remove Duplicates in a Range: Syntax

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

Range(Address).RemoveDuplicates Columns:=Array(Columns List) 

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

VBA Remove Duplicates in a Range: Examples

The following Excel VBA macro code is to delete duplicates in Range from the worksheet. This VBA macro will delete the records in the range A1 to D10 based on the column 1, 2.

Sub sbRemoveDuplicates()
Range(“A1:D10”).RemoveDuplicates Columns:=Array(1,2)
End Sub 

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


Please follow the below steps to execute the VBA code to delete duplicate Rows in a Range 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 range A1 to D10 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 1, 2 which we have mentioned in the above example code.

Explained VBA Code to Delete Active Range

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

Sub sbRemove_Duplicates_in_Range()
‘Here Range refer Range A1 to D10 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.
Range(“A1:D10”).RemoveDuplicates Columns:=Array(1,2)
End Sub
End statement to end the VBA code to remove duplicate records in a Range

You can mention any range and different number of columns to check for the duplicates. Excel will first find the duplicates based on the specified columns. And then it removes the duplicate records in the given range.

LIMITED TIME OFFER
By |January 19th, 2015|VBA|1 Comment

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).

One Comment

  1. Neha Kohli June 16, 2017 at 10:10 PM - Reply

    Hi,

    I’ve numbers of 16 digits, and this macro is not working for this. Could you suggest ?

    Thanks.

Leave A Comment


Related pages


advanced vba excel examplestimevalue in excelprogramming excel vbaexcel sql tablerun vba codevba filestraining schedule template excelsimple project charter template freehow to unlock excel workbookinternetexplorer.application vbahow to remove duplicates from excel sheetexcel merge cells with dataexcel look up functionsactivate sheet vbaexcel countif formula exampleexcel vertical lookupfor loop in excel vbashortcut key in excelexcel 2007 macros tutorialexcel macro to copy and pastesave excel vbavisual basic excel 2007 tutorial pdfvba rename filehyperlinking in excelexcel formula explainedvba open access databasehow to use iserror in excelsimple macro program in excelusing vlookup in vbadml statements in sql servervba excel select rowexcel 2007 activex controlsapplication displayalertsselect range in excel vbaexcel how to delete blank rowshow to delete duplicate items in excelunprotect sheet excel 2007using the sumif function in excelsum if condition in excelcheck activexexcel automatic color codingiferror function excel 2010vba return value from userformlistbox selectedto find duplicate records in excelmicrosoft excel substituteexcel function lookupmaster sheet excelchart creation in excelunshare excel spreadsheetexcel vba delete pivot tablemysql dsn connection stringhow to use count function in excel 2007excel vba unload meproject issue tracker excel templatevba access recordsetmicrosoft excel templates project managementexcel dashboards tutorialhow to use the vlookup functioncountif vba excelexcel combine data from multiple sheets into one sheetexcel count duplicates in columnfind duplicates in a columnlock an excel fileexcel row colorhow to delete a column in excelgetrows vbavba code to save workbookfor loop vba excelaccess vba sql updatevba access connection stringvlookup function in excel 2007interview questions and answers for fresherproject plan template excelhow do i delete blank rows in excelsumif function in excelhyperlink excel vbahow do i remove blank rows in excel 2010message vbadata validation in excel 2010 tutorialinternetexplorer.application vba