+ Reply to Thread
Results 1 to 5 of 5

macro: changing cell color based on count in cell

  1. #1
    Registered User
    Join Date
    07-02-2008
    Location
    Winnipeg, MB
    Posts
    57

    macro: changing cell color based on count in cell

    Hi,

    I need help writing a macro. Column D is filled with various dates. D2 might be 2, D3 might be 55, etc. Also, the number of rows is unknown and may be as large as a thousand or more. There also might be blank cells in the column too.

    I need a macro that will go through Column D and change the Fill Color based on criteria:

    - If the count in the cell is less than 25, the cell's fill color should change to red

    - If the count in the cell is the same or more than 25, the cell's fill color should change to green

    Thanks!

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    You don't need a macro for that.. you can use built in Conditional Formatting

    Select entire column D and go to Format|Conditional Formatting

    Cell Value Is >> Greater than or equal to >> enter: =25

    click Format and go to Pattern tab to choose your colour (green)

    Click Ok.

    Click Add

    Cell Value is >> Greater than >> enter: =0

    Click Format and choose colour (red)

    Click Ok

    Click Ok to finish.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    07-02-2008
    Location
    Winnipeg, MB
    Posts
    57
    Quote Originally Posted by NBVC
    You don't need a macro for that.. you can use built in Conditional Formatting

    Select entire column D and go to Format|Conditional Formatting

    Cell Value Is >> Greater than or equal to >> enter: =25

    click Format and go to Pattern tab to choose your colour (green)

    Click Ok.

    Click Add

    Cell Value is >> Greater than >> enter: =0

    Click Format and choose colour (red)

    Click Ok

    Click Ok to finish.
    Okay, and what if I wanted the column beside the count to say:

    "low" if the count in the cell is less than 25, the cell's fill color should change to red

    "high" if the count in the cell is the same or more than 25, the cell's fill color should change to green

    P.S. you're an excel genius lol

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    you would enter a formula in the cell.

    e.g. =if(d1<25,"low","high")

    if you want those cells coloured too, then select that column and invoke the Conditional Formatting...

    Cell Value Is >> equal to >> enter: ="low"

    choose red format..

    Click Add

    Cell Value Is>> equal to >> enter: ="high"

    Choose green format

  5. #5
    Registered User
    Join Date
    07-02-2008
    Location
    Winnipeg, MB
    Posts
    57
    Quote Originally Posted by NBVC
    you would enter a formula in the cell.

    e.g. =if(d1<25,"low","high")

    if you want those cells coloured too, then select that column and invoke the Conditional Formatting...

    Cell Value Is >> equal to >> enter: ="low"

    choose red format..

    Click Add

    Cell Value Is>> equal to >> enter: ="high"

    Choose green format
    You're a genius, thanks a bundle.

+ 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