List Attributes in column M for every match found in Category Name (Column A)

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
580
Office Version
  1. 365

Raw Data:-

COLUMN ACOLUMN M
ID NumberAttribute
11111Horse
11111Cat
11111Dog
11112Spiderpig
11112Dog
11112Horse
11113Dog
11114Cat
11114Horse
11113Horse
11113Spiderpig
11113Cat
11113Penguin
11111Penguin

Desired Outcome (New Sheet)
Column AColumn BColumn CColumn DColumn EColumn FColumn GColumn H
IDMatch 1Match 2Match 3Match 4Match 5Match 6Match 7
11111HorseCatDogPenguin
11112SpiderpigDogHorse
11113DogHorseSpiderpigCatPenguin
11114CatHorse


There are over 10,000 rows in the spreadsheet (with approx 200 Unique IDS).

In Column M there ar a potential of 800 matches, but believe there should be no more than 20 in each unique ID that needs to be captured.

Thanks!
 

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.
This should work.
I don't know how your dataset looks like, so I took range("A1:M15) for example.

VBA Code:
Sub jec()
 Dim ar As Variant, a As Variant, i As Long
 ReDim sp(1000) As Variant
 ar = Sheets(1).Range("A1:M15")
 
 With CreateObject("scripting.dictionary")
   For i = 2 To UBound(ar)
     a = .Item(ar(i, 1))
     If IsEmpty(a) Then a = sp
        a(0) = ar(i, 1)
        a(UBound(a)) = a(UBound(a)) + 1
        a(a(UBound(a))) = ar(i, 13)
       .Item(ar(i, 1)) = a
   Next
   Sheets(2).Cells(2, 1).Resize(.Count, UBound(a)) = Application.Index(.items, 0, 0)
 End With
     
End Sub
 
Upvote 0
Could be done pretty easily with power query aswell
 
Upvote 0
This should work.
I don't know how your dataset looks like, so I took range("A1:M15) for example.

VBA Code:
Sub jec()
 Dim ar As Variant, a As Variant, i As Long
 ReDim sp(1000) As Variant
 ar = Sheets(1).Range("A1:M15")
 
 With CreateObject("scripting.dictionary")
   For i = 2 To UBound(ar)
     a = .Item(ar(i, 1))
     If IsEmpty(a) Then a = sp
        a(0) = ar(i, 1)
        a(UBound(a)) = a(UBound(a)) + 1
        a(a(UBound(a))) = ar(i, 13)
       .Item(ar(i, 1)) = a
   Next
   Sheets(2).Cells(2, 1).Resize(.Count, UBound(a)) = Application.Index(.items, 0, 0)
 End With
   
End Sub
thanks very much for your help :)...... Just realised is it possible to also include Column I and have it return for "YES" only please?
 
Last edited:
Upvote 0
Like this?

VBA Code:
Sub jec()
 Dim ar As Variant, a As Variant, i As Long
 ReDim sp(1000) As Variant
 ar = Sheets("Blad1").Range("A1:M15")
 
 With CreateObject("scripting.dictionary")
   For i = 2 To UBound(ar)
     a = .Item(ar(i, 1))
     If IsEmpty(a) Then a = sp
        a(0) = ar(i, 1)
        If ar(i, 9) = "YES" Then
           a(UBound(a)) = a(UBound(a)) + 1
           a(a(UBound(a))) = ar(i, 13)
          .Item(ar(i, 1)) = a
        End If
   Next
   Sheets("Blad2").Cells(2, 1).Resize(.Count, UBound(a)) = Application.Index(.items, 0, 0)
 End With
     
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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