Results 1 to 17 of 17

compare values in two cells, highlight when there is no match.

Threaded View

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    32

    compare values in two cells, highlight when there is no match.

    I have a simple macro problem. I have two cells with values that are strings.

    I would like to know of a macro that can compare each two cells(start from E2 and compare with E3)to see if the values are NOT equal.
    If they are equal, do nothing and if they are NOT, highlight the value.

    example:
    compare E2&E3, E4,E5,E6,E7,.... if for example E2&E3, E4,E5,E6,E7,.... each has same string, do nothing, but if they were not the same highlight it with red.

    this code checks two cells and highlights one cell when there is duplicate, I like the opposit one, but dont know what to change!

    Sub CompareCells()
    Dim r As Range, cell As Range
    Range("E2", Range("E" & Rows.Count).End(xlUp)).Name = ("MyRange")
    Range("MyRange").Select
    ' clear all colors from selection
    Selection.Interior.ColorIndex = xlNone
    ' loop through cells and compare
    Set r = Selection
    Set r = Selection.Resize(r.Rows.Count + 1)
    
    For Each cell In r
    
    If cell.Offset(1, 0).Value = cell.Value Then
        cell.Offset(1, 0).Interior.ColorIndex = 3
    End If
    Next
    End Sub
    Thanks for your help.
    Attached Files Attached Files
    Last edited by frhling; 01-03-2013 at 07:32 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1