+ Reply to Thread
Results 1 to 11 of 11

macro for conditional formatting based on the comparing values from adjacent columns

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    macro for conditional formatting based on the comparing values from adjacent columns

    Hi

    I need to create a macro which will compare the values in two columns and if values does not match then it should highlight those cells.
    for example:
    column A column B
    1 abcd abcd
    2 abce abcd

    Commission Exception Discompare 11-16-2012.xls
    Last edited by jkmasurkar; 12-14-2012 at 12:03 PM.

  2. #2
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    can someone please help me with it!!

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    if i am correct, you want to compare 2 cells in the same row M and N.

    you dont need a macro for this, you can use regular conditional formatting
    1. highlight the range you want to apply the conditional formatting to
    2. on the home tabe, styles, select CF
    3. select new rule, select use formula
    4. enter =$L2<>$M2 format fill yellow
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    Do you just need to do conditional formatting, or do you really need a macro? This is easily done with built-in conditional formatting. But here is a macro

    Please Login or Register  to view this content.
    To do this with conditional formatting, use this formula and apply it to $D:$S
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    hey i am getting this error when i try to run the macro. please check the screenshot below
    Attached Images Attached Images

  6. #6
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    and formula is also not working , please let me know if i am doing any mistake.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    Here is a solution [jkmasurkar=conditional formatting when adjacent columns do not match=Commission Exception Disco.xlsm] that uses conditional formatting. It also includes the code if you want to try it. I did miss the End With somehow.

  8. #8
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    Hi Jazzer

    Thanks for your help so far. i really appreciate it.
    i got one error, I am attaching the screenshots with the message. please see if you can help me!
    Attached Images Attached Images

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    I have found the error but frankly there's no reason to bother with code. Just use the conditional formatting I set up. There is no advantage to doing this with code.

    Please Login or Register  to view this content.
    I tested this code and am seeing other issues with it also. The conditional format that is set turns out to be

    =AND(ROW(XFC1048564)>1,OR(AND(ISEVEN(COLUMN(XFC1048564)),XFC1048564<>XFD1048564),AND(ISODD(COLUMN(XFC1048564)),XFC1048564<>XFB1048564)))

    I do not know why the cell reference turns out like that; it's the lower-rightcorner of the entire universe, and it doesn't produce the right results.

  10. #10
    Registered User
    Join Date
    10-18-2012
    Location
    hartford
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    when i try to use the formula , it just highlights right bottom corner cell even if they are identical

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: macro for conditional formatting based on the comparing values from adjacent columns

    When you try to use which formula? The one in post #9 is an example of why the code is NOT working.

    Just reference the file I posted in post #7. It uses the correct conditional formatting formula, as shown in post #4. That formula is specific to the SAFARI worksheet layout and allows you to use a single condition. If you try to copy it to other layouts it may not give you what you want. It assumes that data in the even-numbered columns will be compared to the data in the column immediately to the right, and columns to be compared are D:S.

    The approach described by FDibbins above is much simpler but requires a condition for each pair of columns to be compared. If that is easier for you to work with you may want to try that.

+ 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