+ Reply to Thread
Results 1 to 18 of 18

Compare two columns (conditional formatting)

  1. #1
    Registered User
    Join Date
    11-13-2009
    Location
    Quad Cities, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Compare two columns (conditional formatting)

    I'm trying to do a comparison of two entire columns (H & L) where I'm trying to find the data where H < L and then flag those cells as red.

    I tried to do a conditional formatting and put it in like (=$H:$H < $L:$L), and choose to flag each of those cells as red. The issue that I receive is that it states that I cannot perform this task on a range, but only use one cell. Granted I could do this for 500 cells, but I'd rather not key in the formula for every cell.


    I tried to just do it for one and copy and paste (special - formula only) to the other cells, and for some reason, it still takes the actual "text/number" from that cell and pastes it over all of the other cells, so now I have identical cells, that don't do a comparison...

    I don't know if this can be performed with conditional formatting, or if it would be easier to write it as VBA and do it that way -- I am open to suggestions.

    Thanks in advance.


    Notes: These cells are numbers only with a header (in text), and I'm performing this on Office 2007.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Compare two columns (conditional formatting)

    Hi,

    From what you say it suggests you are copying and pasting the formula. You need to copy and paste special the FORMATS.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-13-2009
    Location
    Quad Cities, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare two columns (conditional formatting)

    When I do Paste Special (Formats) all of the other cells just get the formatting of the first cell, even if the rule doesn't apply to them.
    What happened was I wrote the formula to be "=$H$2<$L$2". In this case H2 is less than (<) L2, so it changed it to "Light Red Fill with Dark Red Text".

    When I copy that over to the other cells (Format) it takes that format (the red fill/text) and changes the other cells to that even if they are not less than the corresponding L (or L2 for that matter).

    Any other thoughts?

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Compare two columns (conditional formatting)

    First delete any of your conditional formatting that you set up. Then Select your range in H (e.g. H2:H500) and go to conditional formatting and New Rule>"Format Only Cells that Contain" set it to "less than" and type in your first cell in the other column (L2). Unfortunately with 2007, it'll change L2 to "L2" so you need to edit the rule and remove the quotes.

    Now do the same with column L except using "Greater than" H2. Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    11-13-2009
    Location
    Quad Cities, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare two columns (conditional formatting)

    I removed all conditional formatting and started over. Did as you mentioned as far selecting the range and then choosing L2. When I did that it flagged all of the cells in H that were less than L2...doing the reverse (as mentioned) it flags all of the cells in L that are less than H2. I'm not sure if that's what you were thinking would happen or not.

    What I really need to know is:
    H2<L2
    H3<L3
    ...
    H400<L400
    etc.

    I've attached a sample of the spreadsheet (with all personal data removed). The only thing remaining are the 'H' and 'L' columns.
    Hopefully this helps.

    Thanks again.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Compare two columns (conditional formatting)

    I created this conditional formatting exactly as I described in my previous post. Here's the result.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-13-2009
    Location
    Quad Cities, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare two columns (conditional formatting)

    interesting....I'm not quite sure why this didn't work the first time (or more likely, what I screwed up); however, what you've (ChemistB) done seems to work perfectly.

    Thank you very much. This will save a lot of headache in the future.

    As far as I'm concerned this thread can be closed.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Compare two columns (conditional formatting)

    Hi Stephen,

    Can I just say I thought your award of a negative reputation for my response was undeserved. The first one I've ever had in over 2500 postings.

    Your question was somewhat ambiguous and with the best will in the world we are not mind readers. You didn't bother to upload a workbook in the first instance which makes answering even more difficult.

    Your mention of ending up with 'identical cells' clearly led me to thing that you were inadvertently copying cells rather than formats, and that of course was my first suggestion. I have no way of knowing how skilled you are with Excel and hence how much allowance to make.

    All in all I'm rather disappointed. A negative response was not called for IMO. Yes give a negative response if someone is deliberately unhelpful, or off hand or rude or dismissive, but can I suggest you don't in future mark someone down just because they haven't answered an ill-defined question and are trying to help you.

    Rgds,

  9. #9
    Registered User
    Join Date
    06-15-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Compare two columns (conditional formatting)

    Quote Originally Posted by ChemistB View Post
    I created this conditional formatting exactly as I described in my previous post. Here's the result.
    ChemistB - thanks very much. Works like a charm :-)

  10. #10
    Registered User
    Join Date
    06-19-2012
    Location
    Oman
    MS-Off Ver
    Excel 2010
    Posts
    4

    Thumbs up Re: Compare two columns (conditional formatting)

    Can someone help me with this , i got the concept , but the issue here is it isnt comparing with column it is comparing with first column itself.

    Please help , attached file is here

    http://www.mediafire.com/view/?jl9qu63laa65gol

    Also please explain how do you do that.

    Thanks in Advance
    Attached Files Attached Files

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two columns (conditional formatting)

    Ganesh,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  12. #12
    Registered User
    Join Date
    06-15-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Compare two columns (conditional formatting)

    Hi, while on the topic of comparing two columns to conditionally format a true condition, i'm wondering if it is possible (elegantly) to compare if values in column A are "near" the values in column B, of the corresponding row. For example, if value in A1 ,B1 is 92 and 100 respectively, is it possible to say " draw a red box when A1 is in the range of +/- 10% of B1" - effectivly giving a true condition when A1 is within the range 90-110. Is it possible to work with values like => 0.9*B1, for instance? Thanks in advance. :-)

  13. #13
    Registered User
    Join Date
    11-05-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Compare two columns (conditional formatting)

    I had been pulling my hair out for an hour trying to do exactly this. Thanks for the tip.

  14. #14
    Registered User
    Join Date
    08-22-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Compare two columns (conditional formatting)

    @ChemistB

    Thanks a ton for uploading the file. After pulling my hair out for sometime, because I was doing exactly as prescribed, I realized that my spreadsheet was exported from Access. This for some reason was preventing any conditional formatting to work. So I decided to copy & paste the values into a new worksheet and then it worked! So presto!

    Your directions worked perfectly, just needed to start on a blank spreadsheet.

  15. #15
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Compare two columns (conditional formatting)

    Here is a slightly different way of entering the formula for the Conditional Formatting that you want. It uses one rule but is applied to two ranges.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  16. #16
    Registered User
    Join Date
    09-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    1

    Cool Re: Compare two columns (conditional formatting)

    Quote Originally Posted by ChemistB View Post
    I created this conditional formatting exactly as I described in my previous post. Here's the result.
    Thank you for this post. I was having the same issue and even struggled a couple of times to get this to work. Then I realized that excel had added "" around the cell and once I removed them per your instructions it worked perfectly.

    Thanks!!!

  17. #17
    Registered User
    Join Date
    09-29-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Compare two columns (conditional formatting)

    This was very helpful. Thank you.

  18. #18
    Registered User
    Join Date
    05-30-2013
    Location
    Heredia, Costa Rica
    MS-Off Ver
    Excel 2003/ 2007/ 2010
    Posts
    6

    Re: Compare two columns (conditional formatting)

    Use a formula to do the conditional formatting...

    1. Clear all conditional formatting.
    2. Select both colums.
    3. Conditional Formatting -> New rule
    4. Use a formula to determine which cells to format
    5. Type in the formula: =$L2<$H2. LOCK the column reference, not the row reference!!!)
    6. Set desired format.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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