Transposing Data - Multiple Entries horizontally for the same values from A column

GoranH

New Member
Joined
May 15, 2019
Messages
8
Good day people,

I have a list that looks like this


NameThing
Bobapple
Annpear
Mariedog
Bobcat
Mariewhite
Annred
Georgeblack
Annpurple

I need it to look like this



Bobapplecat
Annpearredpurple
Mariedogwhite
Georgeblack

Help would be very appreciated. About a year ago one of your members helped me with the same issue.

However that solution doesn't work at all anymore.

If it helps, all my "Names" are in A column, and all the "things" are in the B column.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
all my "Names" are in A column, and all the "things" are in the B column.
Assuming that and columns to the right are empty, try this with a copy of your data

VBA Code:
Sub Rearrange()
  Dim a As Variant
  Dim d As Object
  Dim i As Long
  
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  For i = 1 To UBound(a)
    d(a(i, 1)) = d(a(i, 1)) & ";" & a(i, 2)
  Next i
  With Range("D2:E2").Resize(d.Count)
    .Value = Application.Transpose(Array(d.Keys, d.Items))
    .Columns(2).TextToColumns DataType:=xlDelimited, Tab:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 9)
    .Rows(0).Value = Array("Name", "Things")
  End With
End Sub

My data & results:

GoranH 1.xlsm
ABCDEFGH
1NameThingNameThings
2BobappleBobapplecat
3AnnpearAnnpearredpurple
4MariedogMariedogwhite
5BobcatGeorgeblack
6Mariewhite
7Annred
8Georgeblack
9Annpurple
Sheet1
 
Upvote 0
How about
VBA Code:
Sub GoranH()
   Dim Ary As Variant
   Dim i As Long
  
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   With CreateObject("scripting.dictionary")
      For i = 2 To UBound(Ary)
         .Item(Ary(i, 1)) = .Item(Ary(i, 1)) & Ary(i, 2) & "|"
      Next i
      Sheets("Sheet2").Range("A2").Resize(.Count, 2).Value = Application.Transpose(Array(.keys, .items))
   End With
   With Sheets("Sheet2")
      .Range("B:B").TextToColumns .Range("B1"), xlDelimited, , , False, False, False, False, True, "|"
   End With
End Sub
Beaten 2it
 
Upvote 0
Thanks to both you, sincerely.

I've tried Peter's solution first and it worked, so I'll go with that.

Have a nice day guys, and thanks for the help!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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