Tweak this code?

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,041
Office Version
  1. 365
Platform
  1. Windows
I'm using this code to identify duplicates and what I hoped for was that the cell of any duplicates would be highlighted but that isn't happening. All I get is a screen message saying "Ambiguous name detected. Compare data."

My code is:

Sub CompareData()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, dic As Object
Set srcWS = Sheets("First Class")
Set desWS = Sheets("T20")
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 = 24
End If
Next i
Application.ScreenUpdating = True
End Sub

Many thanks. Mel

P.S. I couldn't use the button to post my code.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Good to hear you got the solution.
If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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