Consulting

Results 1 to 3 of 3

Thread: Compare cells and highlight on a result

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    34
    Location

    Compare cells and highlight on a result

    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

  2. #2
    VBAX Regular
    Joined
    Feb 2009
    Posts
    34
    Location
    By the way the code does not work. Any thoughts?

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    See if this works for you:
    [VBA]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
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •