+ Reply to Thread
Results 1 to 13 of 13

format cell color based on another cells value

  1. #1
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    format cell color based on another cells value

    I asked this before and was told to used conditional formatting however I cannot because I have up to 12 conditions and excel 2003 only accepts 3 in conditional formatting, however I found the following code via google that someone posted that would change cell color based on values.

    Please Login or Register  to view this content.
    The google question was "Hi, I need to automate the colouring of cells in F:F, G:G, and H:H when the individual cell value equals a certain value (for the example sake let's say if it's closed a Time and Date will fill these cells, if it is not closed the cell is blank or filled with a hifen ("-"), I need to colour the "open" cells)."

    MY problem is I don't know VBA well enough to change the code and apply it to my situation - Here's an example of what I want to do:

    If value in A1 = 1 set color in B1 to green
    A1 = 2 set color in B1 to orange
    etc

    I would need to test about 12 values and set to 12 different colors. In the above code and question I don't know what is meant by a closed cell. and I don't know what cells the code is evaluating.

    Could someone help me to adapt this code to my example above?

    Thanks much!!
    Last edited by zbor; 09-12-2015 at 04:35 PM.

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: format cell color based on another cells value

    Columns 6,7 and 8 are columns F,G and H
    and each cell means all cells in those columns

    Kind regards
    Leo

  3. #3
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: format cell color based on another cells value

    Hi,

    Here's some other code you could use (based on something I used to use before my company moved on from 2003):
    Please Login or Register  to view this content.
    I've only done the first two figures/colours, but hopefully you can see how it works.

    Good luck.

    Regards,
    Aardigspook

    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark Thread as Solved'.
    You don't need to give me rep if I helped, but thanks are appreciated.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: format cell color based on another cells value

    Another .. variant on your posting. The ColorIndex settings are just random.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: format cell color based on another cells value

    Thanks for the explanation - I will experiment in adapting to what I want.

  6. #6
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: format cell color based on another cells value

    Thanks so much and I will try it out.

  7. #7
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: format cell color based on another cells value

    Thanks - I will try this option also - Appreciate all the expert help.

  8. #8
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: format cell color based on another cells value

    Hi Aardigspook,

    I have entered the adjustments to your code and am getting no visable results. For background - The only macro's I have created were done via the macro recorder, so i don't know if I'm entering the code correctly or how to envoke the code. Here's the steps I've done.

    I selected tools>macros>visual basic editor and entered this version of your example code:

    Please Login or Register  to view this content.
    Then I selected 'Debug>Compile VBA Project

    *** Initially I didn't have the "End Sub" line and it gave an error - then I added "End Sub" and reran the compile and it didn't give an error message or a successful compile message.

    Nothing happened with my color scheme so can you help me to know how to envoke the code???

    Thanks, much apprecitated

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: format cell color based on another cells value

    In VBA, double click on the worksheet that you want to add the code to : this should bring up a blank form . Copy the code into this form.

    Go to your worksheet and type 1 into AB3: cell AE3 will be green. Type 4 and cells AE3 will be orange.

    See attached.
    Attached Files Attached Files
    Last edited by JohnTopley; 09-14-2015 at 11:44 AM.

  10. #10
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: format cell color based on another cells value

    Sorry - I should have explained that the code was worksheet code, not code for a module. Follow JohnTopley's instructions and you should be fine.

    @JohnTopley - thanks for picking up the small ball I dropped...

    Regards,
    Aardigspook

    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark Thread as Solved'.
    You don't need to give me rep if I helped, but thanks are appreciated.

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: format cell color based on another cells value

    No problem: returning the help you have given me previously.

  12. #12
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: format cell color based on another cells value

    Hello John,

    Yes, that is working ideally - Thanks so much for your expertise!! I will close this thread now

  13. #13
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: format cell color based on another cells value

    Glad to see you got what you needed and that I/we could help.

    Regards,
    Aardigspook

    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark Thread as Solved'.
    You don't need to give me rep if I helped, but thanks are appreciated.

+ 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: 8
    Last Post: 06-27-2015, 03:21 PM
  2. Replies: 3
    Last Post: 07-01-2014, 01:51 PM
  3. [SOLVED] change fill color of a range of cells based on color of a cell?
    By DarMelNel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2014, 04:48 PM
  4. Replies: 5
    Last Post: 10-24-2013, 05:34 PM
  5. [SOLVED] Color-format a cell which contains data in a column based on the color of another cell
    By Nit3hawK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2013, 05:25 PM
  6. Delete row based on cell FORMAT (color, font, etc) (not based on cell value)
    By trobey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2012, 10:39 AM
  7. How do i auto fill cell color based on other cells' color?
    By Kchatza in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2012, 05:00 AM

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