+ Reply to Thread
Results 1 to 10 of 10

Loop procedure to change color of 36 shapes based on cell value

  1. #1
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Loop procedure to change color of 36 shapes based on cell value

    Hello all! I am stuck trying to find the best way to loop the code to change each of 36 shapes based on the values in corresponding 36 cells. The only code I have been able to find is

    If IsNumeric(Target.Value) Then
    If Target.Value < 0.15 Then
    ActiveSheet.Shapes("Freeform 45").Fill.ForeColor.RGB = RGB(235, 241, 222)
    ElseIf Target.Value >= 0.15 And Target.Value <= 0.199 Then
    ActiveSheet.Shapes("Freeform 45").Fill.ForeColor.RGB = RGB(216, 228, 188)
    ElseIf Target.Value >= 0.2 And Target.Value < 0.249 Then
    ActiveSheet.Shapes("Freeform 45").Fill.ForeColor.RGB = RGB(196, 215, 155)
    Else
    ActiveSheet.Shapes("Freeform 45").Fill.ForeColor.RGB = RGB(118, 147, 60)
    End If

    This works but requires me to somehow nest these IFs and I would have to manually change the shape names in the code. Is there way to have the code to change the color run for each cell in a range and change the color of its corresponding shape based on the value? Conditional formatting won't work I think because I have a non-standard shape.

    Thanks so much in advance for any and all help!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop procedure to change color of 36 shapes based on cell value

    With no sample I can't test it but maybe something like:

    Please Login or Register  to view this content.
    Last edited by xladept; 03-17-2017 at 05:47 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Loop procedure to change color of 36 shapes based on cell value

    Thanks so much for your quick reply. But from what I can see from your code, I am not clear how I would change the OTHER 35 shapes. The name "Freeform 45" is the name for only one of the shapes. So I'm hoping to find a way to reference the CELL which contains the name of the shape...and have it somehow use the value of that cell to recognize the shape to change the color of. And then of course repeat that for each of the 36 cells that have data.

    Basically the table is:

    County %Pop ShapeName
    Baker .25 Freeform 45
    Lake .15 Freeform 17
    etc
    etc

    Betsy

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop procedure to change color of 36 shapes based on cell value

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  5. #5
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Loop procedure to change color of 36 shapes based on cell value

    Thank you so much! Attached is a sample of what I'm trying to do with a before and after sheet.
    Attached Files Attached Files

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop procedure to change color of 36 shapes based on cell value

    Hi Betsy,

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 03-18-2017 at 05:46 PM.

  7. #7
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Loop procedure to change color of 36 shapes based on cell value

    Thank you SO much! That works perfectly! Now I just need to learn more about FFS and FFC. I truly appreciate your help!
    Betsy

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop procedure to change color of 36 shapes based on cell value

    You're welcome!

    FFC is a variant used to hold the RGB
    FFS is a String used to hold the Free Form Shape

  9. #9
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Loop procedure to change color of 36 shapes based on cell value

    Thanks, that does help me understand. Would this work for a picture as well? For example, I created these as shapes. But, if I used Photoshop or Illustrator to more accurately create the images and imported them into Excel as pictures, would this still work?

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop procedure to change color of 36 shapes based on cell value

    It's kind of like magic, if you have the name, you can do what you want

    And, 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 color of shapes based on a value on another sheet
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2016, 05:41 PM
  2. Query change the Shapes color by entering value in cell
    By ashokJan in forum Excel General
    Replies: 5
    Last Post: 12-05-2014, 07:09 AM
  3. Change color of shapes based on cell values.
    By rkostner in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-24-2013, 05:55 PM
  4. Loop through data points and change color based on label
    By rodrignj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2013, 09:38 AM
  5. Help with loop to fill color of shapes (US map)
    By harleyberger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2012, 01:50 PM
  6. Loop through shapes and alter interior color
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2009, 08:33 AM
  7. Replies: 1
    Last Post: 04-13-2006, 07:30 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