Finding ID number of duplicate entries

amitz

New Member
Joined
Mar 2, 2014
Messages
5
Hello everybody.

I have a long list of people (First and Last names) and their one off ID numbers ( no one has the same number but some have the same names).

I am trying to locate all the duplicate entries and in column D to write the ID number of the duplicate entries - there could be 2-8 duplicates. If there were no duplicates then to write NA.

ID NumberFirst NameLast NameID Number of duplicate (required assistance)
123BenCook567, 789, 105
234FredJayNA
345GregLucasNA
567BenCook123, 789, 105
678GaryPage103
789BenCook123, 567, 105
100LucyGray107, 109
101SamHanesNA
103GaryPage678
105BenCook123, 567, 789
107LucyGray100, 109
109LucyGray100, 107

<tbody>
</tbody>


Thanks for your help and time.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this:-
Results start "D2"
Code:
[COLOR="Navy"]Sub[/COLOR] MG08Jun50
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] R [COLOR="Navy"]As[/COLOR] Range, Twn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] nR [COLOR="Navy"]As[/COLOR] Range, Str [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Twn = Dn.Value & "," & Dn.Offset(, 1).Value
    [COLOR="Navy"]If[/COLOR] Not .Exists(Twn) [COLOR="Navy"]Then[/COLOR]
        .Add Twn, Dn
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]Set[/COLOR] .Item(Twn) = Union(.Item(Twn), Dn)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] nR [COLOR="Navy"]In[/COLOR] .Item(K).Offset(, -1)
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] .Item(K).Offset(, -1)
            [COLOR="Navy"]If[/COLOR] Not R = nR [COLOR="Navy"]Then[/COLOR]
                Str = Str & ", " & R.Value
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] R
    nR.Offset(, 3) = Mid(Str, 2): Str = ""
[COLOR="Navy"]Next[/COLOR] nR
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] [COLOR="Navy"]Resume[/COLOR] [COLOR="Navy"]Next[/COLOR]
 Rng.Offset(, 2).SpecialCells(xlCellTypeBlanks) = "N/A"
[COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] GoTo 0
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Thank you for your help and time.

After running the code on the data, a number of results are correct, others are partially correct and others incorrect.

I have included the results in column D in BOLD.

Unfortunately, my coding experience isn't sufficient in order to edit the code by myself and point out what should be edited.

Could you please take a look again?

Thanks again for your help.



ID NumberFirst NameLast NameRESULTS WITH CODEID Number of duplicate (required assistance)
123BenCook 567, 105567, 789, 105
234FredJayN/ANA
345GregLucasN/ANA
567BenCook 123, 105123, 789, 105
678GaryPage103103
789BenCookN/A123, 567, 105
100LucyGray 107, 109107, 109
101SamHanesN/ANA
103GaryPage678678
105BenCook 123, 567123, 567, 789
107LucyGray 100, 109100, 109
109LucyGray 100, 107100, 107

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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