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.
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.
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.
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.
‘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.
End statement to end the VBA code to remove duplicate records in a column