Delete duplicates per key in a column

Dag2

New Member
Joined
Jul 3, 2023
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hey everyone,
I posted this earlier as follow-up in a different thread, but I thought it would be wiser to open a new one since its a different issue than the original one.

I want to delete duplicates per key in this table:
Keywords_Search_Klemens.xlsm
AB
1KeyActualCategories
21Informationssicherheit
32Informationssicherheit
43Informationssicherheit
54Vorgaben&Maßnahmen
65Informationssicherheit
75Daten&Informationen
85Informationssicherheit
96Informationssicherheit
106Daten&Informationen
116Informationssicherheit
126Informationssicherheit
136Vorgaben&Maßnahmen
146Vorgaben&Maßnahmen
MappedSource


As you can see the Category "Informationssicherheit" (as well as "Vorgaben&Maßnahmen") appears multiple times at key 6. I want to delete duplicates, so I only have unique Categories per Key.
So it looks like this:
Keywords_Search_Klemens.xlsm
FG
1KeyActualCategories
21Informationssicherheit
32Informationssicherheit
43Informationssicherheit
54Vorgaben&Maßnahmen
65Informationssicherheit
75Daten&Informationen
86Daten&Informationen
96Informationssicherheit
106Vorgaben&Maßnahmen
MappedSource


I wanted to work this out in PowerQuery but couldn`t figure out how to do it, so I am preferably looking for a solution there. Any other solution will be appreciated though!

Thanks in advance for your help!
Best regards,
Klemens
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I wanted to work this out in PowerQuery but couldn`t figure out how to do it,
Probably @alansidman could help.

I can offer a solution with VBA:
VBA Code:
Sub Dag2()
Dim i As Long, j As Long, k As Long, n As Long
Dim va, vb
Dim d As Object

Set d = CreateObject("scripting.dictionary"): d.CompareMode = vbTextCompare
va = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(, 2)
ReDim vb(1 To UBound(va, 1), 1 To 2)

For i = 2 To UBound(va, 1)
 j = i
    Do
        i = i + 1
        If i > UBound(va, 1) Then Exit Do
    Loop While va(i, 1) = va(i - 1, 1)
    i = i - 1
    d.RemoveAll
   
    For k = j To i
        If Not d.Exists(va(k, 2)) Then
            d(va(k, 2)) = Empty
            n = n + 1
            vb(n, 1) = va(k, 1)
            vb(n, 2) = va(k, 2)
        End If
    Next
   
Next

Range("F2").Resize(UBound(vb, 1), 2) = vb

End Sub
 
Upvote 0
Mcode in Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Duplicates" = Table.Distinct(Source)
in
    #"Removed Duplicates"
 
Upvote 0

Forum statistics

Threads
1,223,875
Messages
6,175,117
Members
452,613
Latest member
amorehouse

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