how to highlights the same value with duplicates in another column

fayez_MrExcel

Active Member
Joined
Oct 29, 2005
Messages
444
Office Version
  1. 365
Platform
  1. Windows
i have multiple employee with the same employee number in column A and a code in column b. how can I highlights the same value with duplicates in column B. Ex:

Col A | Col B
1001 code1
1001 code2
1001 code3
1001 code1
1002 code1
1002 code2
1003 code3
1004 code2
1004 code2

In the above example, i want to highlight emp no. 1001 with the same code1 and emp no. 1004 with same code2.

Note. i want to highlight both emp no. and the code

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Assuming your data starts in row 1, try:
Code:
Sub CompareLists()
    Application.ScreenUpdating = False
    Dim Rng As Range, RngList As Object
    Set RngList = CreateObject("Scripting.Dictionary")
    For Each Rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
        If Not RngList.Exists(Rng.Value & Rng.Offset(0, 1).Value) Then
            RngList.Add Rng.Value & Rng.Offset(0, 1).Value, Nothing
        Else
            Rng.Resize(, 2).Interior.ColorIndex = 3
        End If
    Next
    RngList.RemoveAll
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
thanks Mumps... it works but i wanted to highlighted all 1001 with code1 and 1004 with code2. Thanks
 
Upvote 0
How about this mod to mumps code
Code:
Sub CompareLists()
    Application.ScreenUpdating = False
    Dim Rng As Range, RngList As Object
    Set RngList = CreateObject("Scripting.Dictionary")
    For Each Rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
        If Not RngList.Exists(Rng.Value & Rng.Offset(0, 1).Value) Then
            RngList.Add Rng.Value & Rng.Offset(0, 1).Value, [COLOR=#0000ff]Rng[/COLOR]
        Else
            Rng.Resize(, 2).Interior.ColorIndex = 3
            [COLOR=#0000ff]RngList(Rng.Value & Rng.Offset(0, 1).Value).Resize(, 2).Interior.Color = vbRed[/COLOR]
        End If
    Next
    RngList.RemoveAll
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
yeah that works great thanks fluff and thanks mumps.... have a great day ahead
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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