+ Reply to Thread
Results 1 to 17 of 17

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

  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!

    Please Login or Register  to view this content.
    Thanks for your help.
    Attached Files Attached Files
    Last edited by frhling; 01-03-2013 at 07:32 AM.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    Please Login or Register  to view this content.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

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

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

    Quote Originally Posted by Fotis1991 View Post
    Please Login or Register  to view this content.
    Thanks. but It just worked for E2&E3 and not for other cells.
    Last edited by frhling; 01-03-2013 at 06:20 AM.

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    ....Thanks. but It just worked for E2&E3 and not for other cells.
    No this is not correct. I just change the equal sign(=) to <>. Nothing else..
    Attached Files Attached Files

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

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

    Quote Originally Posted by Fotis1991 View Post
    No this is not correct. I just change the equal sign(=) to <>. Nothing else..
    Thanks but It is not what I want.
    I thought by <> which you mentioned the problem can be solved. but seems not.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    You are welcome.

    ...I thought by <> which you mentioned the problem can be solved. but seems not.
    The problem that you described to us in your first post is solved using this. If you want something else then i believe that you must describe your request better or even better to upload a sample workbook.

    Good luck.

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

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

    Quote Originally Posted by Fotis1991 View Post
    You are welcome.



    The problem that you described to us in your first post is solved using this. If you want something else then i believe that you must describe your request better or even better to upload a sample workbook.

    Good luck.
    Thanks Fotis. I have editted my 1st post.
    hope this time u get what I mean

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    In your example, E6 & E9 are highlighted. Which is the correct result and why?

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

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

    Quote Originally Posted by Fotis1991 View Post
    In your example, E6 & E9 are highlighted. Which is the correct result and why?
    Both are correct.
    E2=E3 -> do nothing
    E4=E5 -> do nothing
    E6 -> is not the same as its adjacent cell so should be highlighted
    E7=E8 -> do nothing
    E9 -> is not the same as its adjacent cell so should be highlighted

    and this should continue...

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

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

    Quote Originally Posted by Fotis1991 View Post
    In your example, E6 & E9 are highlighted. Which is the correct result and why?
    Both are correct.
    E2=E3 -> do nothing
    E4=E5 -> do nothing
    E6 -> is not the same with its adjacent cell so should be highlighted
    E7=E8 -> do nothing
    E9 -> is not the same with its adjacent cell so should be highlighted

    and this should continue...

  11. #11
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    Ok. As in the example sheet everything is as you describe in your latest post(#10) and as for you the result is not good, i give up! This does no sense for me. Maybe someone else could understand better than me and will able to helps you. Good luck!

  12. #12
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

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

    Quote Originally Posted by Fotis1991 View Post
    Ok. As in the example sheet everything is as you describe in your latest post(#10) and as for you the result is not good, i give up! This does no sense for me. Maybe someone else could understand better than me and will able to helps you. Good luck!
    @Fotis1991, what I think he wants is to compare the values on adjacent rows, so the value on row 2 with the value on row 3, and then 4 with 5 and so on.

    The trick will be when it finds a mismatch as happens with row 6, which is why it is highlighted. It then should highlight and IGNORE row 6, and start the comparison process again by looking at rows 7 and 8, which are fine, hence no highlight.

    Then row 9 is different from row 10, so row 9 is highlighted, skipped and the comparison restarts by comparing row 10 with 11.
    If you like my contribution click the star icon!

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

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

    This would produce that result

    Please Login or Register  to view this content.

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

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

    Quote Originally Posted by Olaf.Braxhoofden View Post
    @Fotis1991, what I think he wants is to compare the values on adjacent rows, so the value on row 2 with the value on row 3, and then 4 with 5 and so on.

    The trick will be when it finds a mismatch as happens with row 6, which is why it is highlighted. It then should highlight and IGNORE row 6, and start the comparison process again by looking at rows 7 and 8, which are fine, hence no highlight.

    Then row 9 is different from row 10, so row 9 is highlighted, skipped and the comparison restarts by comparing row 10 with 11.
    @Fotis: u tried ur best. Thanks a lot for repliyng fast. maybe my explanation was not sufficient.

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

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

    @Olaf.Braxhoofden: Vielen dank yes, and now it works.

  16. #16
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

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

    It's true that VBA is not my best , BUT in this case really i was not able to understand the expected result.

    I am glad that you found your solution.

    @Olaf.Braxhoofden

    Thanks for the explanation. Well done!

  17. #17
    Registered User
    Join Date
    10-29-2012
    Location
    hanoi, VietNam
    MS-Off Ver
    Excel 2007
    Posts
    8

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

    I got this thing, maybe usefull

    HTML Code: 

+ Reply to Thread

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