+ Reply to Thread
Results 1 to 11 of 11

Change the background color of a shape based on the value of a cell

  1. #1
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Change the background color of a shape based on the value of a cell

    Hi,

    Im want to create a mapping of our resort which has around 140 villas. So i will create 140 rectangles representing rooms. I will simply refer their room numbers to a list. The room number list is in Column A, while column B is the room status. Room Status can be OC,OD,VC,VCI,VD, and OOO and each status has its own background color:

    OC = Blue
    OD = Blue
    VC = Dark Green
    VCI = LightGreen
    VD = Brown
    OOO = Red

    Now, I want that If A1 = 1021 and B1 = VC (green) then the 1021 shape will also change to green (copy the background color of the status of 1021).

    Please see attachment for a sample.
    Thank You!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change the background color of a shape based on the value of a cell

    1.
    why arent you using conditional formatting to color your cells in the list


    2.
    do you really need shapes?
    if yes, you should probably name the shapes something meaningful like the room number instead of Rectangle 1, Rectangle 2, etc
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: Change the background color of a shape based on the value of a cell

    Hi humdingaling,

    The sheet uploaded was just a demo to show the positions, I can use conditional formatting ofcourse, but my main goal is that a shape must mimic the color of the referring cell(whatever the color maybe).

    I need shapes since I need to actually copy the rooms positioning in the map as well as their actual shape and distance to each other. Naming the shapes should be easy but I really need its Fill Color to copy the reference cell background.

  4. #4
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: Change the background color of a shape based on the value of a cell

    I updated the sample sheet. I already used conditional formatting, now my only problem is, the shape with the assigned room number must follow the color of that cell.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change the background color of a shape based on the value of a cell

    ok
    try this out then

    the only thing is you need to name your shapes the ROOM number
    and as long as the shape name length is between 3 and 5
    it will automatically update


    i added another piece of code that will help insert the text in the shape based on the shape name

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change the background color of a shape based on the value of a cell

    ps if you dont want to use conditional format then the syntax would be
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: Change the background color of a shape based on the value of a cell

    Thank you for the code Humdingaling,

    I tried it on my computer, Im out of work so now I'm using Excel 2016. Your code works perfectly as I want to. I will try it tomorrow in our office using Excel 2007. Hopefully, it will work.

    Thank you so much!
    I will update tomorrow.

  8. #8
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: Change the background color of a shape based on the value of a cell

    Hi Humdingaling,

    So i tried it in Excel 2007, run the macro and came an error "Object doesnt support this property and method" Run-time error "438".
    When I try to debug, this line was highlighted in yellow:

    Please Login or Register  to view this content.
    So i removed the .DisplayFormat, but then the shapes wont follow the color of the cell, instead it shows white.

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change the background color of a shape based on the value of a cell

    gah forgot displayformats doesnt work on 2007
    Please Login or Register  to view this content.
    change the code to above instead
    it manually does the selecting of color in the code itself
    change RGB to what suits you
    http://dmcritchie.mvps.org/excel/colors.htm
    This is what i used as resource for RGB numbers

    alternatively you can go back to manually coloring in the cells and using this line instead
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: Change the background color of a shape based on the value of a cell

    Thank You Hum,

    Now it works perfectly. Here is my sample:

    Sample Output.png

    Thank you... Till next time!

  11. #11
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Change the background color of a shape based on the value of a cell

    glad to see it working

    thanks for the rep

+ 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. change shape color based on a cell value on another sheet
    By aleenkhan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2017, 11:14 AM
  2. VBA: Change Shape Color based off cell value
    By emmz5d in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2016, 04:35 PM
  3. Change cell background color based on another cells background color
    By Queo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 06-10-2014, 05:28 AM
  4. [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
  5. Change Shape Color based on Cell Values
    By obriend in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2013, 03:26 AM
  6. Change Background Color Based On Cell
    By radicalrom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 10:58 AM
  7. Change Background Color of Row Based on Cell Value
    By ashishashish8 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-21-2011, 02:51 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