PDA

View Full Version : Compare cells and highlight on a result



viomman
11-04-2009, 08:25 AM
I am trying to loop through cells to compare to a range on another sheet. If two criterias match i want the row to highlight. Here is my code so far
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant

Set CompareRange = Worksheets("Active Projects").Range("A1:A500")
Range("U" & ActiveCell.Row & "").Select
For Each x In Selection
For Each y In CompareRange
If x = y & Range("F" & ActiveCell.Row & "") = "7681" Then cell.EntireRow.Interior.ColorIndex = 4
Next y
Next x
End Sub

viomman
11-04-2009, 10:02 AM
By the way the code does not work. Any thoughts?

lucas
11-04-2009, 09:54 PM
See if this works for you:
Option Explicit
Sub a()
Dim i As Long
Dim finalRow As Long
finalRow = Sheet1.Cells(Rows.Count, 13).End(xlUp).Row
For i = 2 To finalRow
If Sheet1.Range("M" & i) = Sheet2.Range("N" & i) Then
Sheet1.Rows(i).Interior.Color = vbYellow
Sheet2.Rows(i).Interior.Color = vbYellow
End If
Next i
Sheets("Sheet2").Select
End Sub