VBA check for duplicates in column B in excel 2003

dilipgr

New Member
Joined
Jan 30, 2015
Messages
43
I need a macro that when I run it will check for duplicate names in column b, if a duplicate is found I would like a message box to pop up letting me know there are duplicates and the value in column A they are in. Now the below coding i use but i need the value in column A
Thanks

Dim dict As Object
Dim LR As Long, i As Long, v As Variant, strResult As String

Set dict = CreateObject("Scripting.Dictionary")

With Sheets("Sheet1")
LR = .Range("b" & .Rows.Count).End(xlUp).Row
For i = 2 To LR
If WorksheetFunction.CountIf(.Columns("b"), .Range("b" & i).Value) > 1 Then
If dict.Exists(.Range("b" & i).Value) Then
dict.Item(.Range("b" & i).Value) = dict.Item(.Range("b" & i).Value) & .Range("b" & i).Row & ","
Else
dict.Add .Range("b" & i).Value, .Range("b" & i).Row & ","
End If
End If
Next i
End With

For Each v In dict.keys
strResult = strResult & "Complaints: " & v & vbNewLine & "Rows: " & _
Left(dict.Item(v), Len(dict.Item(v)) - 1) & vbNewLine & vbNewLine
Next v
MsgBox strResult
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,216,384
Messages
6,130,309
Members
449,571
Latest member
Jay Zyller

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