REAL-TIME

VBA Projects

Full Access with Source Code
  • Designed and Developed by PNRao

  • Full Access with VBA Source Code

  • Well Commented Codes Lines

  • Creative and Professional Design

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:
  • 50+ Excel Templates

  • 50+ PowerPoint Templates

  • 25+ Word Templates

Share Post

VBA highlight duplicates in a column Excel Macros Examples Codes: to highlight all duplicate records in a column in MS Excel 2003, 2007, 2010, 2013. We will also see the practical VBA example for highlighting the duplicates in a Column.

VBA highlight duplicates in Column

VBA code to Highlight Duplicates in Column

Here is the Example VBA syntax and Example VBA Macro code to highlight duplicates in a Column in Excel. This will help you to know how to highlight duplicate records in a column using VBA.

VBA highlight Duplicates in Column: Procedure

Following is the VBA Syntax and sample VBA macro command to highlight duplicates in a Column of Worksheet using VBA. In this method we loop through all the records and identify the duplicates using VBA.

VBA Highlight Duplicates in a Column: Examples

The following Excel VBA macro code is to highlight duplicates in a column. This VBA macro will loop through the all the items in the first column and identify the duplicates using Match Spreadsheet Function. Here the logic is, the number is unique if the match index equals to the current processing row number. Otherwise it will be duplicate, it will highlight column in Yellow.

Sub sbHighlightDuplicatesInColumn()
    Dim lastRow As Long
    Dim matchFoundIndex As Long
    Dim iCntr As Long
    lastRow = Range("A65000").End(xlUp).Row

    For iCntr = 1 To lastRow
    If Cells(iCntr, 1) <> "" Then
        matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" & lastRow), 0)
        If iCntr <> matchFoundIndex Then
            Cells(iCntr, 2) .Interior.Color = vbYellow
       End If
    End If
    Next
End Sub

Instructions to run the VBA Macro code to highlight duplicates in a Column

Please follow the below steps to execute the VBA code to highlight duplicates in Column.

  • 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 values in Column 1. Make sure that you have some duplicate items in the data for testing purpose.
  • Now press F5 to Execute the macro and test the code

Now you can observe the code is loop thronging all the items in the column 1. And identifying the duplicates and Highlighting the duplicated cell in Yellow color if the values are repeating.

Explained VBA Code to Highlight Duplicates in a Column

Starting Macro program and sub procedure to write VBA code to highlight duplicate records in a Worksheet Column.

  • Declaring the lastRow variable as Long to store the last row value in the Column1
  • Declaring the variable MatchFoundIndex is to store the match index values of the given value
  • Declaring the variable iCntr is to loop through all the records in the column 1 using For loop
  • Highlighting the last row in the Column 1
  • looping through the column1
  • Checking if the cell is having any item, skipping if it is blank.
  • Getting match index number for the value of the cell
  • If the match index is not equals to current row number, then it is a duplicate value
  • Highlighting the duplicated cell in Yellow color

Here is the commented code explained to highlight the duplicates in a column:

Sub sbHighlightDuplicatesInColumn_C()
'Declaring the lastRow variable as Long to store the last row value in the Column1
    Dim lastRow As Long
'matchFoundIndex is to store the match index values of the given value
    Dim matchFoundIndex As Long
'iCntr is to loop through all the records in the column 1 using For loop
    Dim iCntr As Long
'Highlighting the last row in the Column 1
    lastRow = Range("A65000").End(xlUp).Row

'looping through the column1
    For iCntr = 1 To lastRow
        'checking if the cell is having any item, skipping if it is blank.
        If Cells(iCntr, 1) <> "" Then
            'getting match index number for the value of the cell
            matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" & lastRow), 0)            
            'if the match index is not equals to current row number, then it is a duplicate value
            If iCntr <> matchFoundIndex Then
                'Highlighting the duplicated cell in Yellow color
                Cells(iCntr, 2) .Interior.Color = vbYellow
            End If
        End If
    Next
End Sub 
Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Project Management Templates

All-in-One Pack
120+ Project Management Templates

Essential Pack
50+ PM Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project
Management Template
Ultimate Resource
Management Template
Project Portfolio
Management Templates
Categories: VBATags: Last Updated: June 17, 2022

4 Comments

  1. Francisco Solorzano June 3, 2015 at 7:01 AM

    Buenas noches
    Thanks!
    This macro send error:
    Error of compilation
    Error of Sintaxys
    Help me?

  2. PNRao June 3, 2015 at 12:32 PM

    Hi, Good morning!
    Please provide the example file to understand your data.
    Thanks-PNRao!

  3. Jason Valenzuela August 18, 2016 at 12:13 AM

    Thanks so much, this works great. I was wondering if it’s possible to highlight both/all instances of duplication. This seems to only highlight the duplicate but not the “original”, if that makes sense.

  4. Mahbub December 23, 2019 at 1:36 PM

    Hi, I need to find out duplicate of some specific data from a range. such as from these following values, I need to know 350 and 250 are duplicate or not. As I am new learner of Vba, pls help me. 250,350,400,425,400,325,350

Leave A Comment