+ Reply to Thread
Results 1 to 7 of 7

Change shape fill color depending on cell value

  1. #1
    Registered User
    Join Date
    01-22-2010
    Location
    Norway
    MS-Off Ver
    Excel 2007
    Posts
    33

    Smile Change shape fill color depending on cell value

    Hi guys,

    (newbie vba)
    I've been searching the web for the following issue (I just cannot seem to get it to work):

    I've got two shapes in which I want the color to change depending on a drop down list Open/closed.

    If valve_1 has status "Open" then that corresponding valve is to be filled with green.
    If it is "Closed" it is to be red.
    The same for Valve 2.

    I have uploaded what I've got so far on the basis of an example I have found online, but it just does not work.

    Any help much appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Change shape fill color depending on cell value

    There was no code in that sample to work... So, simplistic code. You may wish to add extra checks to determine if just the dropdown changes.
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,444

    Re: Change shape fill color depending on cell value

    there was code, although incorrect, in the thisworkbook object.

    moved to the sheet object and using the change event

    Please Login or Register  to view this content.
    the code you had will work
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    01-22-2010
    Location
    Norway
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Change shape fill color depending on cell value

    reference to cytop answer:

    Awesome, it works, one thing though.
    How did you know to put "3" and "5" as the reference to those shapes? When I select them, "valve_1" and "valve_2" appear.
    I've added a new third valve, but how do I find the shape name to put in to the code?

    Update: just since his code was more simple
    Last edited by xe-dingo; 08-30-2013 at 07:52 AM.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,444

    Re: Change shape fill color depending on cell value

    Alternative using a UDF

    code in standard code module
    Please Login or Register  to view this content.
    in a cell use formula

    =udfVALVECOLOR("Valve_1",IF(L9="OPEN",65280,255))

    65280 is RGB(0,255,0)

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Change shape fill color depending on cell value

    there was code...
    So there is - I double clicked on the ThisWorkBook module for another workbook - Duh!

    As far as the shape names go, you can simply use
    Please Login or Register  to view this content.
    I just hacked some code together quickly after assuming there was none...

  7. #7
    Registered User
    Join Date
    01-22-2010
    Location
    Norway
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Change shape fill color depending on cell value

    Hi guys,
    Thanks so much for the help.
    At the moment I am using the following code which is working perfectly:

    Please Login or Register  to view this content.
    Only thing is, that I would now like to have three color options instead of just two. OPEN=Green, CLOSED=Red and NA=White.
    How can this be incorporated in to the code? any help MUCH 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. [SOLVED] Change Shape Fill Color Based on Cell Value
    By Justair07 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-28-2013, 09:35 AM
  2. Add command button to shape and change shape color on mouseover
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2012, 05:12 PM
  3. Change cell fill when changed different color depending on the day
    By rev0jace in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2012, 11:06 AM
  4. Fill Cell with Color from Shape's color code
    By excelnewbie80 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-02-2012, 05:34 PM
  5. Replies: 3
    Last Post: 07-08-2010, 06:48 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