Extract unique data from column and associate data

Exceladd1ct

Board Regular
Joined
Feb 10, 2019
Messages
76
Hello, i need a VBA code that will extract the unique values from column A
2020-12-06_14h40_03.png

and associate it's data from column B
2020-12-06_14h40_12.png

So far i only managed to extract unique data from col A into an Array.


Thanks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
With Power Query
Phone BrandPhone ColorPhone BrandPhone Color
AppleredApplered,blue,maroon,orange
SamsungblueSamsungblue,red,yellow,white
AppleblueHuaweiblack,white,red,green,blue
Applemaroon
Huaweiblack
Samsungred
Huaweiwhite
Huaweired
Appleorange
Huaweigreen
Huaweiblue
Samsungyellow
Samsungwhite

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Phone Brand"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Phone Color", each List.Distinct([Count][Phone Color])),
    Extract = Table.TransformColumns(List, {"Phone Color", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
    Extract
 
Upvote 0
How about
VBA Code:
Sub Exceladd1ct()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, 1).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & ", " & Cl.Offset(, 1).Value
         End If
      Next Cl
      Range("E2").Resize(.Count, 2).Value = Application.Transpose(Array(.Keys, .Items))
   End With
End Sub
 
Upvote 0
Solution
Thanks. Both methods are working.
I am just curious if there is an "arrays" approach to this. Because that's what i've tried.
 
Upvote 0
You could do it with a normal array rather than a dictionary, but it would be more complicated & slower.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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