Combine rows based off column id

hcanning

New Member
Joined
May 3, 2018
Messages
2
Hi ,
I'd like to know how to merge rows based off unique id values. Lets say I have:
IDName
@345Jack
@532Mary

<tbody>
</tbody>

and another sheet with
IDAge
@34532
@53238

<tbody>
</tbody>
...
I'd like to be able to combine sheets based off id to append data
IDNameAge
@345Jack32
@352Mary38

<tbody>
</tbody>
...my real wold example will be comparing 500 rows or so and appending numerous columns based off the id
Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi & welcome to the board.
How about this
Code:
Sub GetInfo()
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
   Set Ws2 = Sheets("[COLOR=#ff0000]Sheet2[/COLOR]")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 1).Value
      Next Cl
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 2).Value = .Item(Cl.Value)
      Next Cl
   End With
End Sub
Change sheets names in red to suit.
This will take the data in Col B on sheet2 & add it to col C on sheet1
 
Upvote 0
Hi & welcome to the board.
How about this
Code:
Sub GetInfo()
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
   Set Ws2 = Sheets("[COLOR=#ff0000]Sheet2[/COLOR]")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 1).Value
      Next Cl
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 2).Value = .Item(Cl.Value)
      Next Cl
   End With
End Sub
Change sheets names in red to suit.
This will take the data in Col B on sheet2 & add it to col C on sheet1

Thanks...where do I run that. Excel novice.
 
Upvote 0

Forum statistics

Threads
1,215,408
Messages
6,124,727
Members
449,185
Latest member
ekrause77

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