Check for duplicates in column

In this article, we have created a macro to highlight duplicate values.

Raw data consists of different car names. We want to highlight duplicate entries.

ArrowSampleData

Press the “Highlight duplicate” button to run the macro and highlight duplicate entries.

ArrowOutput

Logic explanation

We have created “Check_Dups” macro to highlight duplicate entries. They will be highlighted in red color. In the macro, we check for count of a particular entry. If it is greater than 1, then the data will be highlighted.

ArrowOutput

 

Please follow below for the code


Option Explicit

Sub Check_Dups()

'Declaring variables
Dim Cell As Variant
Dim Source As Range

'Initializing source range
Set Source = Range("A9:A24")

'Removing any previous formatting from the source
Source.Interior.Color = RGB(221, 235, 247)

'Looping through each cell in the source range
For Each Cell In Source
    
    'Checking whether value in cell already exist in the source range
    If Application.WorksheetFunction.CountIf(Source, Cell) > 1 Then
        
        'Highlighting duplicate values in red color
        Cell.Interior.Color = RGB(255, 0, 0)
        
    End If
Next

End Sub

 

If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.

We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube