+ Reply to Thread
Results 1 to 8 of 8

Conditional Formatting, 3 conditions, relative to the previous rows cell

  1. #1
    Registered User
    Join Date
    09-18-2016
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    4

    Question Conditional Formatting, 3 conditions, relative to the previous rows cell

    I have created a spreadsheet for financial data, where I want to be able to change the fill colour of the cell based on relative value of the cell on its left.

    Ex.
    Please Login or Register  to view this content.
    Based on this information I would like a couple of things to be done by the conditional formatting. I assume either an IF, OR, or XOR function will be used but correct me if I'm wrong. (which I probably am based on the fact that I can't figure this out by myself and have come here)

    I want to be able to:

    IF A1<B1 then B1 is green

    IF A2>B2 then B2 is red

    IF A3=B3 then B3 is white


    I want to be able to control the colour of each cell (excluding the first cell in every row because there is no value to its left) based on its value in comparison to the cell on its immediate left (the previous cell in its row). But, I want to be able to do this in bulk because I have almost 500 cells with data that need comparison. I want it to have 3 conditions as I stated:

    green if the value in the cell is higher than the cell to its left

    red if the value in the cell is lower than the cell to its left

    white if the value is equal to the cell on its left

    Thanks for all the answers and advice.
    Last edited by rlubin; 09-18-2016 at 02:39 PM. Reason: used code tags to preserve spacing of data example

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

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    You are just about there. You need three rules, one for each condition. The rules are going to look similar to what you showed, and will apply to B1:Z99 where Z99 is the lower-right cell in your range. Except I think the three rules you really want are:

    =A1<B1 then B1 is green

    =A1>B1 then B1 is red

    =A1=B1 then B1 is white

    Use the "Use a formula" option.

    Another thing you can do, instead of making three rules is just make the first two. Then format all the cells to be white. Then they will be white unless one of the first two conditions is true. Same effect, fewer rules.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-18-2016
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    Dear 6StringJazzer,

    Thank you for you quick response and insight.

    I didn't make it super clear in my thread, but I need to apply those equations to every single cell with data inside of it. So, B1>C1 is just a simplifed version. I would actually like to have the formula apply to every single cell, relative to the cell to its left. Because I plan to apply this to a large amount of data I would prefer not to write:

    B3>C3, C3>D3, E3>D3...etc

    B3<C3, C3<D3, E3<D3...etc

    The second part of my question being:

    I would like the formula to take into account the value of very cell to its left (the previous cell in such row) in the entire worksheet, not just A1, B1 and C1.

    You have covered how to make the rule apply to all the data, but I also need to know how to make the formula compare a cell only to the previous cell in its row (the cell on its left), how would I go about doing that using references.

    And is it possible to only use 2 rules that would cover what i require?

  4. #4
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    Yes. You can, if you don't have any color on any cells. Or you must have to create 3 rules for that. Click on B1, then create all 3 new rules with formula.
    1st Rule :
    Please Login or Register  to view this content.
    . Then set the color to green.
    2nd Rule :
    Please Login or Register  to view this content.
    . Then set the color to white.
    3rd Rule :
    Please Login or Register  to view this content.
    . Then set the color to red.

    Now go to Manage rules on Conditional formatting and replace the =$B$1 with your desired range (ex. =$B$1:$AA$10000). If you have no color in any cell then there is no need to create the 2nd rule as all the cells are white by default.

    That's it.
    Last edited by sanram; 09-18-2016 at 01:09 PM.

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

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    The way that conditional formatting works is to define the rule in terms of the cell in the upper left corner of the range you want to format. If you write a rule that says

    =A1<B1

    you can apply that one rule to the entire range B1:Z99.

    If you are still confused I can just install these rules into your file if you attach it.

    You can use just two rules by following my earlier instructions.

  6. #6
    Registered User
    Join Date
    09-18-2016
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    Thanks for both of your responses, I still can't seem to get it to work I am uploading the file now, it is incomplete but it was have all the numbers needed to test whether of not the CF works properly.

    Just to make sure we are all on the same page I wrote what colours the boxes should be and why, just encase I haven't explained myself well enough.

    Thanks again ladies(maybe) and gentlemen(probably).
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    Because you don't know one basic rule of creating conditional formatting. You have to write the formula for the 1st cell of your selected range. As your 1st cell is B3 and range is B3:J14 then you need to select B3:J14 first, then create those two rules. But you have to use A3 & B3 there instead of A1 & B1. Hope that make sense now. See the attachment.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-18-2016
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Conditional Formatting, 3 conditions, relative to the previous rows cell

    Thanks all for help, solved.

+ 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. Conditional Formatting for previous cell change
    By no.18shirt in forum Excel General
    Replies: 14
    Last Post: 07-02-2013, 07:14 AM
  2. Conditional formatting, three colour scale, how to use relative cell
    By marcopietro in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-12-2012, 07:38 AM
  3. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  4. Conditional formatting with a relative cell.
    By roontoon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 07:05 PM
  5. Replies: 3
    Last Post: 04-06-2011, 01:15 PM
  6. Conditional Formatting 4+ conditions, format rows based on cell
    By nockam in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-12-2006, 06:12 PM
  7. Replies: 3
    Last Post: 12-31-2005, 05:56 AM
  8. Conditional Formatting of Rows Based On More Than 4 Conditions
    By TRenick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2005, 12: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