+ Reply to Thread
Results 1 to 6 of 6

format cell colour dependant on comparison to target value and 0

  1. #1
    Registered User
    Join Date
    04-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    3

    Red face format cell colour dependant on comparison to target value and 0

    Hi,

    I have a spreadsheet with columns for Client, Target DC%, The actual figure attainted last 3 months and the DC% year to date which looks like this:

    Client TargetDC% DC% last 3 months DC% YTD
    1 4% -1% -51%
    2 31% 57% 57%
    3 45% 51% 28%


    I need to create a macro that will highlight the cells in Columns C and D based on the criteria below but to highlight the background of the cell that the number is in not update a new cell. This same criteria should be applied to both column C and column D values versus those in column B.

    =IF(AND(C2 >B2,C2>0),"Green",IF(AND(C2 <B2,C2>0),"Amber",IF(AND(C2 <B2,C2<0),"Red","none")))


    I made some progress in that I can get it to check one of the items, e.g. highlight if cellC2>B2 but not the additional greater than zero check or all the others!

    I do hope I am not repeating another post but I have tried and tried to find the answer!

    Any help would be greatly received as its sending me crazy. I know excel pretty well but am no programmer so the macro element has me dizzy.

    Thanks in advance

    Kirsten
    Attached Files Attached Files
    Last edited by Kirsten2010; 04-29-2010 at 07:12 AM. Reason: adding example attachment

  2. #2
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    re: format cell colour dependant on comparison to target value and 0

    Kristen - Im fairy good with Macros and would like to help but im not sure I understand your issue here.

    Can you please clarify?

  3. #3
    Registered User
    Join Date
    03-28-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    29

    re: format cell colour dependant on comparison to target value and 0

    Hey Kristen,

    Try this code:

    Please Login or Register  to view this content.
    To put it in your workbook, press Alt+F11 and paste the above code in there.
    Warm regards,

    Shampoo Monkey

    If you are happy with the results, please add to my reputation by clicking the icon next to the Post # in the bar above this post.

  4. #4
    Registered User
    Join Date
    04-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    3

    Thumbs up re: format cell colour dependant on comparison to target value and 0

    That works perfectly, thank you so much.

    The achieved values (columns C & D) change each month, I asssume I have to manually run the macro every time I change the values? Wasn't sure if there is ever an automatically update option - no biggy if not.

    Thanks again and also to day92 for the offer.

    Kirsten

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help to format cell colour dependant on comparison to target value and 0

    Why do you need a Macro for this ? Surely conditional formatting would suffice ?

    Using your sample file, highlight C2:D14 and apply the following Conditional Formatting "FormulaIs" Rules:

    Rule 1
    =AND(C2>$B2,C2>0)
    format Green

    Rule 2
    =AND(C2<$B2,C2>0)
    format Amber

    Rule3
    =AND(C2<$B2,C2<0)
    format Red

    as the values alter so too will the formatting.


    EDIT:
    @shampoo monkey, FWIW, in the below:

    Please Login or Register  to view this content.
    only BVal is a Double - all others are declared as Variants - not sure if that was the intention or not - it always makes sense (IMO) to declare variables which will store whole numbers > 255 (or < 0) as Longs
    (Integers get converted to Long under the hood)
    Last edited by DonkeyOte; 04-29-2010 at 04:24 AM.

  6. #6
    Registered User
    Join Date
    04-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    3

    Thumbs up Re: format cell colour dependant on comparison to target value and 0

    How right you are. Had managed to overlook the fact you can put in a formula rather than just checking 'cell value is' with conditional formatting.

    Thanks to you all so much. This kind of help is invaluable and I really appreciate that you guys take the time to help people out.

    Kirsten

+ 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