Search a list for "almost" duplicates with Macro

CESRingberg

New Member
Joined
May 17, 2015
Messages
6
Hi! :cool:

I have a long list of company names, and some columns of data about them.
I have removed all duplicates from the list, but I still have some "almost" duplicates that i need to find.

I found below code on the internet and made a Command button using the code, and it works okay but can someone please help me decipher the code so I can tweak it to work perfect :)

It marks some names that I’m not sure why and it leaves some that are almost identical like:

"Company" & "Company A/S" are not highlighted

I'm pretty new to VBA so any help will be greatly appreciated

Code:
[FONT=Monaco]Sub TestForDups()[/FONT]

[FONT=Monaco]    Dim LLoop As Integer[/FONT]
[FONT=Monaco]    Dim LTestLoop As Integer[/FONT]
[FONT=Monaco]    Dim LClearRange As String[/FONT]

[FONT=Monaco]    Dim Lrows As Integer[/FONT]
[FONT=Monaco]    Dim LRange As String[/FONT]
[FONT=Monaco]    Dim LChangedValue As String[/FONT]
[FONT=Monaco]    Dim LTestValue As String[/FONT]

[FONT=Monaco]    'Test first 200 rows in spreadsheet for uniqueness[/FONT]
[FONT=Monaco]    Lrows = 200[/FONT]
[FONT=Monaco]    LLoop = 2[/FONT]

[FONT=Monaco]    'Clear all flags[/FONT]
[FONT=Monaco]    LClearRange = "A2:A" & Lrows[/FONT]
[FONT=Monaco]    Range(LClearRange).Interior.ColorIndex = xlNone[/FONT]

[FONT=Monaco]    'Check first 200 rows in spreadsheet[/FONT]
[FONT=Monaco]    While LLoop <= Lrows[/FONT]
[FONT=Monaco]        LChangedValue = "A" & CStr(LLoop)[/FONT]

[FONT=Monaco]        If Len(Range(LChangedValue).Value) > 0 Then[/FONT]

[FONT=Monaco]            'Test each value for uniqueness[/FONT]
[FONT=Monaco]            LTestLoop = 2[/FONT]
[FONT=Monaco]            While LTestLoop <= Lrows[/FONT]
[FONT=Monaco]                If LLoop <> LTestLoop Then[/FONT]
[FONT=Monaco]                    LTestValue = "A" & CStr(LTestLoop)[/FONT]
[FONT=Monaco]                    'Value has been duplicated in another cell[/FONT]
[FONT=Monaco]                    If InStr(Range(LTestValue).Value, Range(LChangedValue).Value) > 0 Then[/FONT]
[FONT=Monaco]                        'Set the background color to red[/FONT]
[FONT=Monaco]                        Range(LChangedValue).Interior.ColorIndex = 3[/FONT]
[FONT=Monaco]                        Range(LTestValue).Interior.ColorIndex = 3[/FONT]

[FONT=Monaco]                    End If[/FONT]

[FONT=Monaco]                End If[/FONT]

[FONT=Monaco]                LTestLoop = LTestLoop + 1[/FONT]

[FONT=Monaco]            Wend[/FONT]

[FONT=Monaco]        End If[/FONT]

[FONT=Monaco]        LLoop = LLoop + 1[/FONT]
[FONT=Monaco]    Wend[/FONT]

[FONT=Monaco]End Sub[/FONT]
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,222,695
Messages
6,167,691
Members
452,131
Latest member
MichelleH77

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