Two dynamic lists on two sheets. Check for and identify duplicates. How?

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,041
Office Version
  1. 365
Platform
  1. Windows
I have two dynamic lists of names, both in column B on sheets "First Class" and "T20". What I would like to do is run a macro(?) on sheet "T20" that will check the list of names on the "First Class" sheet and highlight any duplicates in there might be in column B on the "T20" sheet.

How may I achieve this, please?

Mel
 

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)
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, dic As Object
    Set srcWS = Sheets("T20")
    Set desWS = Sheets("First Class")
    v1 = srcWS.Range("B2", srcWS.Range("B" & Rows.Count).End(xlUp)).Value
    v2 = desWS.Range("B2", desWS.Range("B" & Rows.Count).End(xlUp)).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v2) To UBound(v2)
        If Not dic.exists(v2(i, 1)) Then
            dic.Add v2(i, 1), i + 1
        End If
    Next i
    For i = LBound(v1) To UBound(v1)
        If dic.exists(v1(i, 1)) Then
            desWS.Range("B" & dic(v1(i, 1))).Interior.ColorIndex = 3
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this on a copy of your Workbook as unexpected results may occur. Place code in ThisWorkbook of your VBE
VBA Code:
Sub FindDuplicates()
Dim wb As Workbook, sht1 As Worksheet, sht2 As Worksheet, srchRng As Range, fndRng As Range, cell As Range
Dim lRowSht1 As Integer, lRowSht2 As Integer, m As Range
Set wb = ThisWorkbook: Set sht1 = wb.Sheets("First Class"): Set sht2 = wb.Sheets("T20")
lRowSht1 = sht1.Columns("B").Rows.End(xlDown).Row: lRowSht2 = sht2.Columns("B").Rows.End(xlDown).Row
Set fndRng = sht1.Range("B2:B" & lRowSht1): Set srchRng = sht2.Range("B2:B" & lRowSht2)
For Each cell In srchRng
    Set m = fndRng.Find(cell.Value, LookAt:=xlWhole)
    If Not m Is Nothing Then
        cell.Interior.Color = 65535
    End If
Next cell
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,993
Messages
6,175,845
Members
452,675
Latest member
duongtruc1610

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