View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Compare two worksheets and Highlight duplicates in each

Give this a whirl...

Sub Find_MatchesINZips()

Dim compareRange As Range
Dim x As Range, y As Range

Set compareRange = Worksheets(2).Range("A2:A149")

For Each x In Selection
For Each y In compareRange
If x.Value = y.Value Then y.EntireRow.Interior.ColorIndex = 6
Next y
Next x

End Sub
--
HTH...

Jim Thomlinson


"Lisab" wrote:

PLEASE HELP!
I am trying to highlight every row in a worksheet that has a duplicate in
another worksheet in the same excel file.

I have never programmed in excel but I am very skilled at VBA.

I am using the following code. However, it errors out in the IF THEN
statement.

***Unable to set the Pattern property of the interior class**

I also tried using the ColorIndex property and I get the same error-
Selection.Rows(counter).Interior.ColorIndex = vbYellow
---------------
Sub Find_MatchesINZips()

Dim compareRange As Variant
Dim x As Variant, y As Variant
Dim counter As Integer

Set compareRange = Worksheets(2).Range("A2:A149")
counter = 1

For Each x In Selection
For Each y In compareRange
If x = y Then Selection.Rows(counter).Interior.Pattern = vbYellow
Next y
counter = counter + 1
Next x

End Sub