VBA to remove all kinds of duplicates in excel

nagasree

New Member
Joined
Oct 30, 2021
Messages
30
Office Version
  1. 2019
Platform
  1. Windows
I have a excel file which needs to be unique, I want to remove the duplicates, all kinds of duplicates like below

1674636877688.png


Going to data->remove duplicates is not working. i found a code, which is also not working

Sub SimpleExample()
ActiveSheet.UsedRange.RemoveDuplicates Columns:=Array(1, 2, 3) , Header:=xlYes
End Sub


Can anyone help me with this Thanks in advance
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA to remove all kinds of duplicates
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
This is the closest I can get it with Power Query
Book1
ABCDEFG
1CodeNameValueCodeNameValue
21colormulticolor1colorMulticolor
31colorMulticolor2FruitApple
41color Multicolor2FruitApploe
51colormulti color3CountryUnitedstates
61colorMulti-color
72FruitApple
82Fruitapple
92Fruit Apple
102FruitApple.
112FruitApploe
123Countryunitedstates
133CountryUnited-States
143CountryUnited States
153CountryUnited states
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Trimmed Text" = Table.TransformColumns(Source,{{"Value", Text.Trim, type text}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Trimmed Text",{{"Value", Text.Proper, type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Capitalized Each Word",".","",Replacer.ReplaceText,{"Value"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","-"," ",Replacer.ReplaceText,{"Value"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1"," ","",Replacer.ReplaceText,{"Value"}),
    #"Uppercased Text" = Table.TransformColumns(#"Replaced Value2",{{"Value", Text.Upper, type text}}),
    #"Capitalized Each Word1" = Table.TransformColumns(#"Uppercased Text",{{"Value", Text.Proper, type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Capitalized Each Word1")
in
    #"Removed Duplicates"
 
Upvote 0
You could test this. You will have to adjust the ranges to suit your data location.
All results will have no spaces or non-letter characters in them as I couldn't see how else to make all those items (that clearly are not duplicates) into duplicates.

VBA Code:
Sub Dedupe()
  Dim a As Variant
  Dim i As Long
 
  a = Range("C3", Range("E" & Rows.Count).End(xlUp)).Value
  With CreateObject("VBScript.RegExp")
    .Global = True
    .Pattern = "[^A-Za-z]"
    For i = 2 To UBound(a)
      a(i, 3) = .Replace(a(i, 3), "")
    Next i
  End With
  With Range("H3:J3").Resize(UBound(a))
    .Value = a
    .RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
  End With
End Sub

My sample data (C:E) and code result (H:J)

nagasree.xlsm
CDEFGHIJ
1
2
3CodeNameValueCodeNameValue
41colormulticolor1colormulticolor
51colorMulticolor2FruitApple
61color Multicolor3Countryunitedstates
71colormulti color
81colorMulti-color
92FruitApple
102Fruitapple
112Fruit Apple
122FruitApple.
132FruitApple
143Countryunitedstates
153CountryUnited-States
163CountryUnited States
173CountryUnited states
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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