+ Reply to Thread
Results 1 to 10 of 10

Macro to check values on two cells should be equal

  1. #1
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Macro to check values on two cells should be equal

    Hi all

    I have cells that they're values should be equal B6=B11, B7=B12, B8=B13, E6=B14, E7=B15, E8=B16, I want a macro that if the values are not equal then the background should be RED and a pop up message "The values should be equal".

    Any help on how to do this would be very much appreciated!

    Thanks
    Blokeman

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to check values on two cells should be equal

    Like this:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Macro to check values on two cells should be equal

    Hi stnkynts

    Thank you for response, is it possible that only if B6, B7, B8, E6, E7 and E8 have value then that's the time that it will check the other cells? The priority is always cells B6, B7, B8, E6, E7 and E8, if this cells are blank then it will not check the other cells. Example: if B6 is empty and B11 have a value of 104 then do nothing but if B6 have a value of 103 then it will check B11 if they have the same value. Hope this help, sorry I forgot to mention this on my first post.

    Thanks
    Blokeman

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to check values on two cells should be equal

    Can this help?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Macro to check values on two cells should be equal

    Hi John

    Thanks for your response.
    This is what happened when I run your code:

    -when there's values in cells B11:B16 and B6:B8, E6:E8 is empty, no message no color- Approved

    -when there's values in cells B11:B16 and I entered values in B6:B8, E6:E8 not equal to B6:B16 then I only got a message and no color. And when all cells have values (not equal) and I clear B6:B16 then I got a message and color only on B11:B16. On this one can both cells have color, only if not equal but not if both is empty.

    Hope this help.

    Thanks
    Blokeman

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to check values on two cells should be equal

    See amended code:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Macro to check values on two cells should be equal

    Hi stnkynts

    When I run the amended code:

    -When values in B6 and B11 is not equal I got message but no color on both cell. There should be color when both cells value is not equal.
    -if I delete the value in cell B6 then it turn red. If cells B6:B8, E6:E8 is empty and cells B11:B16 have value then do nothing (no message and no red color background).

    Hope this help.

    Thanks
    Blokeman

  8. #8
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to check values on two cells should be equal

    Post your workbook cause it works fine for me

  9. #9
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Macro to check values on two cells should be equal

    @ stnkynts
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to check values on two cells should be equal

    It is because you are using conditional formatting to color the cells. The conditional formatting is taking precedence over the macro's cell coloring. Conditional Formatting and VBA do not work well together. There may be a way to recognize the conditional formatting, remove it, and change the cell color and if there is I don't know how to do it. Best of luck to you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Ignore If Blank & check multiple cells for equal values
    By Urugmo88 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-25-2013, 04:46 AM
  2. 'All cells equal' check
    By steev_jd in forum Excel General
    Replies: 6
    Last Post: 07-05-2010, 11:20 AM
  3. Macro to check for NULL values in other cells
    By mrw1reless in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2009, 01:51 AM
  4. Check if a number of cells are equal
    By samuelalfred in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-12-2009, 04:20 AM
  5. [SOLVED] check if 2 cells are equal but only if they contain numbers not i.
    By Peter Boardman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-17-2005, 04:06 PM

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