Merging duplicate row IDs

eric1987

New Member
Joined
Nov 20, 2016
Messages
1
I was using a vlookup to get data from an ID, but I have realised that I have duplicate ID's in the database.
I am wanting to merge duplicate row ID's within a database, but keeping all data contained for them.
I am expecting there to be up to a max of 5 duplicates, so repeating the Fruit/Animal/Colour columns up to 5 times to the right.
I also want to be able to keep the highest number in Column B that is attributed to that ID.
ID's are not in numerical order in the database, and contain both numbers and letters.

Please see the following example:

[TABLE="width: 1152"]
<tbody>[TR]
[TD="class: xl66, width: 64"]Currently[/TD]
[TD="class: xl63, width: 64"][/TD]
[TD="class: xl63, width: 64"][/TD]
[TD="class: xl63, width: 64"][/TD]
[TD="class: xl63, width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="class: xl67, width: 64"]Output[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl63"][/TD]
[TD="class: xl63"][/TD]
[TD="class: xl63"][/TD]
[TD="class: xl63"][/TD]
[TD="class: xl63"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]ID[/TD]
[TD="class: xl65"]Number[/TD]
[TD="class: xl65"]Fruit[/TD]
[TD="class: xl65"]Animal[/TD]
[TD="class: xl65"]Colour[/TD]
[TD][/TD]
[TD="class: xl65"]ID[/TD]
[TD="class: xl65"]Number[/TD]
[TD="class: xl65"]Fruit[/TD]
[TD="class: xl65"]Animal[/TD]
[TD="class: xl65"]Colour[/TD]
[TD="class: xl65"]Fruit[/TD]
[TD="class: xl65"]Animal[/TD]
[TD="class: xl65"]Colour[/TD]
[TD="class: xl65"]Fruit[/TD]
[TD="class: xl65"]Animal[/TD]
[TD="class: xl65"]Colour[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"]Bear[/TD]
[TD="class: xl64"]Red[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Blue[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"]Cat[/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Red[/TD]
[TD][/TD]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Red[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"]Cat[/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Yellow[/TD]
[TD][/TD]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Yellow[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"]Ant[/TD]
[TD="class: xl64"]Blue[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]10[/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"]Bear[/TD]
[TD="class: xl64"]Red[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]Apple[/TD]
[TD="class: xl64"]Cat[/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]Cherry[/TD]
[TD="class: xl64"]Cat[/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]Banana[/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

How would I go about doing this in Excel?
Thanks in advance.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
With Data on sheet "Current" and the results on sheet "Output", try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG19Aug07
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR="Navy"]With[/COLOR] Sheets("Current")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range("A2", Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Not Dic.Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
    Dic.Add Dn.Value, Dn.Offset(, 1).Value
[COLOR="Navy"]Else[/COLOR]
[COLOR="Navy"]If[/COLOR] Dn.Offset(, 1).Value > Dic(Dn.Value) [COLOR="Navy"]Then[/COLOR] Dic(Dn.Value) = Dn.Offset(, 1).Value
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Output")
    .Range("A2").Resize(Dic.Count, 2) = Application.Transpose(Array(Dic.Keys, Dic.items))
    .Range("A1:B1").Value = Array("ID", "Number")
[COLOR="Navy"]For[/COLOR] n = 1 To Rng.Count [COLOR="Navy"]Step[/COLOR] 5
    Ac = Ac + 3
    .Cells(1, Ac).Resize(, 3).Value = Sheets("Current").Range("C1:E1").Value
    .Cells(2, Ac).Resize(5, 3).Value = Sheets("Current").Cells(n + 1, 3).Resize(5, 3).Value
[COLOR="Navy"]Next[/COLOR] n
    [COLOR="Navy"]With[/COLOR] .Range("A1").Resize(6, Ac + 2)
         .Borders.Weight = 2
         .Columns.AutoFit
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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