+ Reply to Thread
Results 1 to 17 of 17

Conditional formatting color fill based on nested if statement

  1. #1
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Conditional formatting color fill based on nested if statement

    I need to use a nested if statement to color a cell based on the values of different nonadjacent cells within a row.

    So
    If the Best price = Aldi then color the cell yellow
    If the best price is Lidl then colour the cell orange
    If the best price is Tesco then color the cell blue

    I think I need to use the column that works out the price per 100g/litre etc instead of the actual store price column to do this (in reality the pack sizes may be different so I need these columns to work out the base figure)
    Thanks
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Simpler than that

    In the CF rules, choose "Format only cells that contain" then set cell value Equal to, then choose C2, E2 or G2 for each rule/format.

    I've attached an updated sheet to show what I mean.
    Attached Files Attached Files
    Excel is a constant learning process and it's great to help each other. If any of us have helped you today, a click on the "reputation" star on the left is appreciated.

  3. #3
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Just a thought though...

    What happens if you have two stores with the same price? You would need to change the order of the CF rules and tick the "stop if true" option.

  4. #4
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Brilliant shirleyxls!
    Why does my simple brain always try to complicate things?!

    I want to leave the cell unfilled if there is more than one store with the same price. So would this happen automatically?

  5. #5
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Just noticed that this doesn't work if I use the 'price per' column as the cells in this column contain a formula not a value.

    I've attached if test2 to show what I mean.............
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Hi Tracey,

    For your "equal price" you would need another rule, this time with a formula:

    =COUNTIF($C2:$C2,$I2)>1

    This needs to be the first rule with a "stop if true" check box so that it doesn't try to apply any other rules if you have more than one match. I've created this in the attached updated file so you can see it in action (I used pale grey in the format just so you could see it in action).

    I'm not sure what you want to see in your "price per" column. Do you want the lowest one to be highlighted? If that's the case, would it be better to have an additional "Best price per" column and use a similar rule to your Best Price?

    Shirley
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Hi Shirley

    Sorry, I'm not very good at explaining myself. This is part of a larger spreadsheet so I may have not got it quite right.

    Basically the pack size is often different across the three shops. So the 'Price Per' column provides a base price for them all.

    Therefore, the 'Best Price' column needs to pick up the cheapest 'Price Per' value in a row, as opposed to the shop price columns (as I first thought).

    However, when I try to use these 'Price Per' columns to conditionally format the 'Best Price' column, it doesn't pick up the returned value of the formula in the 'Price Per' columns and so does not colour fill the 'Best Price' cells.

    Thanks
    Tracey

  8. #8
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Hi Tracey,

    I think I see what you mean. All the Price Per calculations on your sample were the same so I think that was what confused me

    On the attached example I've added a new Alt Best Price column which still shows the best price as before, but the conditional formatting is based on the Price Per figure. I still have the COUNTIF as the first rule in case you have 2 with the same value, although I've change it slightly to take into account the minimum Price Per unit.

    The other colours use a formula for the CF instead of the original method. For Tesco for example, the formula is:

    =MIN($D2,$F2,$H2)=$H2

    so checking the minimum price per against each store.

    I changed the Aldi pears Price per formula from C4/8 to C4/24 just to demonstrate the difference. It's the one highlighted in red.

    Just as an aside, would it be better to have your divisor as a column alongside each store rather than embedding these in the formulas? I'm just thinking it would be easier to see the differences and also make it easier for you to change them. I've added a sheet called Alternative to show what I mean
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Ah that makes sense Shirley, thank you so much

    I've attached a screenshot of the opened spreadsheet you sent me though as I'm getting an error in your 'formulas used' columns (it says "the formula contains unrecognized text"). I'm using Excel 2007?

    Thanks again for your patience
    Attached Images Attached Images

  10. #10
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    You can just delete those columns Tracey. I just used them so I could easily see the formulas you'd used in your original sheet - they don't actually do anything

    I'm guessing the =FORMULATEXT function wasn't available in Excel 2007 - I honestly can't remember when it was introduced (I'm using 2016) so must have been a later addition.

    Could you update your profile to indicate you're using 2007? A lot of people don't have access to Excel 2003 anymore (me included!) so sometimes you won't get answers to your posts if people think that's what you're using

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Conditional formatting color fill based on nested if statement

    Quote Originally Posted by shirleyxls View Post
    I'm guessing the =FORMULATEXT function wasn't available in Excel 2007
    The FORMULATEXT function was introduced in Excel 2013.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  12. #12
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Ah I see Shirley. Yes I will do.
    I'm so behind the times it's untrue I've only just started using Excel again in my new job so I'm having to dust the rust off my old system!
    I'm presuming that there wasn't anything in the 2007 that was similar then?

    Thanks too Tony

    You are all most kind and I only wish that I had half of your brains!
    Most appreciative of both your time and your knowledge

  13. #13
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    I've just encountered another problem..........just when you thought it was safe to go back into the water!

    I want to leave the best price column with no fill if there isn't anything in the price per columns. At the moment the CF isn't picking this up (as in row 5 - ifTest4)

    Do I need to add something else in CF to do this?

    I really do need to go back to school :-(
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Updated ifTest4 attached
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Hi Tracey,

    No problem. I've added another simple rule "Format only cells that contain" and set that to no fill if the cell value is equal to 0. I've set this as "stop if true" so it won't try to apply any of the other formats based on minimum values. I've put that on both your original Sheet 1 and the Alternative sheet.

    Updated version attached.

    Shirley

    Tony - thanks for the update on when the FORMULATEXT function was introduced. I find it really useful when I'm analyzing/auditing spreadsheets and it's invaluable for documentation.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    09-25-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Conditional formatting color fill based on nested if statement

    Arghhhh Shirley I'd already tried that but it didn't seem to be working............I've only just realised that I'd set a 'no fill' colour on my duplicate prices too!!!
    The Del Boy phrase of "What a dipstick" comes to mind

    You're a little star Shirley
    Thank you for your continued patience and kindness

    Kindest wishes
    Tracey

  17. #17
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Conditional formatting color fill based on nested if statement

    Or in the words of Homer Simpson "Doh"

    My pleasure to help out... just shout if you're stuck with anything

    Shirley

+ 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. Replies: 21
    Last Post: 12-16-2015, 03:04 PM
  2. [SOLVED] (conditional formatting) color fill whole row based on dates.
    By privatesinn in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-20-2015, 02:00 PM
  3. Copy/paste based on fill color/conditional formatting
    By Wheelie686 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2014, 03:45 PM
  4. [SOLVED] Conditional Formatting not working when applied to nested IF statement
    By mcstaff in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-26-2014, 02:33 PM
  5. [SOLVED] Conditional Formatting with Nested IF Statement I think - Excel 2007
    By Badvgood in forum Excel General
    Replies: 6
    Last Post: 06-04-2014, 11:16 AM
  6. Replies: 10
    Last Post: 06-19-2013, 05:28 PM
  7. Conditional formatting nested IF/AND statement
    By ladygray in forum Excel General
    Replies: 13
    Last Post: 06-16-2010, 09:58 AM

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