VBA Highlight Multiple Names in a Cell

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
I have multiple names in a cell in column A. What I would like to do is to highlight the duplicates as seen below. Any help would be appreciated!

Pete, Pete
Pete, Paul
Al, Joe, James
Jimmy, John, Jimmy
Mike, Jerry, Jerry
Sam, Ray, Ted, Fred
Barry, Jamie, Barry
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Assuming names start in cell A2:
VBA Code:
Sub HiLiteInCellDups()
Dim R As Range, Cel As Range, V As Variant, i As Long, j As Long
Set R = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Application.ScreenUpdating = False
For Each Cel In R
    If InStr(1, Cel.Value, ", ") > 0 Then
        V = Split(Cel.Value, ", ")
        For i = LBound(V) To UBound(V) - 1
            For j = i + 1 To UBound(V)
                If V(i) = V(j) Then
                    Cel.Interior.Color = vbYellow
                    Exit For
                End If
            Next j
        Next i
    End If
Next Cel
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Assuming names start in cell A2:
VBA Code:
Sub HiLiteInCellDups()
Dim R As Range, Cel As Range, V As Variant, i As Long, j As Long
Set R = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Application.ScreenUpdating = False
For Each Cel In R
    If InStr(1, Cel.Value, ", ") > 0 Then
        V = Split(Cel.Value, ", ")
        For i = LBound(V) To UBound(V) - 1
            For j = i + 1 To UBound(V)
                If V(i) = V(j) Then
                    Cel.Interior.Color = vbYellow
                    Exit For
                End If
            Next j
        Next i
    End If
Next Cel
Application.ScreenUpdating = True
End Sub
JoeMo, Perfect! That is exactly what I was looking for! Thank you again for your help and guidance!
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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