CESRingberg
New Member
- Joined
- May 17, 2015
- Messages
- 6
Hi! 
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

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]