VBA for Duplicates Across 13 Columns

mrsbrannon

Board Regular
Joined
Mar 7, 2018
Messages
61
Hello everyone,

I am trying to get a VBA code that will highlight duplicates found across 13 columns of data, possibly 100+ rows of data. So I'm looking for duplicated rows across those 13 columns. See below:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]DOB[/TD]
[TD]Address[/TD]
[TD]Phone[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[/TR]
[TR]
[TD]John Brown[/TD]
[TD]1/1/1992[/TD]
[TD]123 main[/TD]
[TD]1234[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]John Brown[/TD]
[TD]1/1/1992[/TD]
[TD]123 main[/TD]
[TD]1234[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Please note that my data for checking starts in column C, not A. So it's Columns C thru O.

Thank you!:):)
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello everyone,

I am trying to get a VBA code that will highlight duplicates found across 13 columns of data, possibly 100+ rows of data. So I'm looking for duplicated rows across those 13 columns. See below:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]DOB[/TD]
[TD]Address[/TD]
[TD]Phone[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[TD]Etc[/TD]
[/TR]
[TR]
[TD]John Brown[/TD]
[TD]1/1/1992[/TD]
[TD]123 main[/TD]
[TD]1234[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]John Brown[/TD]
[TD]1/1/1992[/TD]
[TD]123 main[/TD]
[TD]1234[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Please note that my data for checking starts in column C, not A. So it's Columns C thru O.

Thank you!:):)

Why not just use conditional format? Otherwise check out xlsupertool Sheet_Comparer rodericke.com/xlsuper
 
Upvote 0
A couple of questions:

1. Can you be more specific about how you are defining what a "duplicate" is? Only names? Only rows? That kind of thing.
2. What do you want to have happen when a duplicate is identified?
 
Upvote 0
[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Phone[/TD]
[TD]State[/TD]
[TD]City[/TD]
[TD]Age[/TD]
[TD]Height[/TD]
[TD]Fav. Color[/TD]
[TD]Fav. Candy[/TD]
[TD]Fav. Food[/TD]
[TD]Blood Type[/TD]
[TD]Hair Color[/TD]
[TD]Eye Color[/TD]
[TD]Coffee or Tea[/TD]
[/TR]
[TR]
[TD]John Brown
[/TD]
[TD]1234[/TD]
[TD]LA[/TD]
[TD]New Orleans[/TD]
[TD]15[/TD]
[TD]5'2[/TD]
[TD]Blue[/TD]
[TD]Nerds[/TD]
[TD]Italian[/TD]
[TD]O+[/TD]
[TD]Brown[/TD]
[TD]Blue[/TD]
[TD]Coffee[/TD]
[/TR]
[TR]
[TD]John Brown[/TD]
[TD]1234[/TD]
[TD]LA[/TD]
[TD]New Orleans[/TD]
[TD]15[/TD]
[TD]5'2[/TD]
[TD]Blue[/TD]
[TD]Nerds[/TD]
[TD]Italian[/TD]
[TD]O+[/TD]
[TD]Brown[/TD]
[TD]Blue[/TD]
[TD]Coffee[/TD]
[/TR]
</tbody>[/TABLE]


1. The sample table shows kinda what I'm looking for in a duplicate. I want to find identical rows (duplicates) across all 13 of those columns. The headers are not these, but this is an idea of how the data lays out (starting with column C)

2. I want it to highlight the duplicate(s) AND original in YELLOW when found

Does that help?
 
Upvote 0
How about
Code:
Sub HighlightDupes()

   Dim Cl As Range
   Dim ValU
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
         ValU = Join(Application.Transpose(Application.Transpose(Cl.Resize(, 13).Value)), ",")
         If Not .exists(ValU) Then
            .Add ValU, Cl
         Else
            .Item(ValU).Resize(, 13).Interior.Color = vbYellow
            Cl.Resize(, 13).Interior.Color = vbYellow
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
How about
Code:
Sub HighlightDupes()

   Dim Cl As Range
   Dim ValU
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
         ValU = Join(Application.Transpose(Application.Transpose(Cl.Resize(, 13).Value)), ",")
         If Not .exists(ValU) Then
            .Add ValU, Cl
         Else
            .Item(ValU).Resize(, 13).Interior.Color = vbYellow
            Cl.Resize(, 13).Interior.Color = vbYellow
         End If
      Next Cl
   End With
End Sub


Thank you! That works when I run the Macro. Is there a way to automate it? Also, is there a way to have it recognize if the rows are totally blank and not highlight duplicate blanks?
 
Upvote 0
This will ignore any row if col C is blank
Code:
Sub HighlightDupes()

   Dim Cl As Range
   Dim ValU
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
         If Len(Cl) > 0 Then
            ValU = Join(Application.Transpose(Application.Transpose(Cl.Resize(, 13).Value)), ",")
            If Not .exists(ValU) Then
               .Add ValU, Cl
            Else
               .Item(ValU).Resize(, 13).Interior.Color = vbYellow
               Cl.Resize(, 13).Interior.Color = vbYellow
            End If
         End If
      Next Cl
   End With
End Sub
As for automating it, when would you want it to run?
 
Upvote 0
I guess when the sheet is opened? The data is collected/pulled over daily/weekly. So either as it's opened or as the data is added? I'm not sure how to phrase that correctly.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top