+ Reply to Thread
Results 1 to 8 of 8

Fill Color for a Group of Shapes

  1. #1
    Registered User
    Join Date
    08-27-2014
    Location
    Florida, U.S.
    MS-Off Ver
    2010
    Posts
    20

    Fill Color for a Group of Shapes

    I have a map of the United States with the following code. When you click a state the color changes from red to blue to white and back again. I have two states (Michigan and Hawaii) that are causing issues. It is because the states are grouped shapes. I have been trying to find a solution for the past week . I have tried several 'if statements', etc to make it work. What am I missing here?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Fill Color for a Group of Shapes

    I am not sure what you mean. Maybe their color is not one of the 3 cases? Case Else can be used to get back on track...
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-27-2014
    Location
    Florida, U.S.
    MS-Off Ver
    2010
    Posts
    20

    Re: Fill Color for a Group of Shapes

    Hi Kenneth,

    Thanks for your reply. I am going to copy the full code below and try to give a better explanation of what is happening. After the election, I wanted to create an electoral map so next election I can try to project the path to Presidency similarly to how the do it on the news. I have a map of the 50 states. With my current code, you click the state and it will change either red, blue or white. This represents Republicans, Democrats and Undecided. The color of the shape feeds into a table that will pull the electoral amount for that state and add them up for the respective party. This code currently works for 48 of the 50 states.

    The two states that do not work are Michigan and Hawaii. Michigan and Hawaii on the map are a group of shapes rather than one individual shape - Hawaii with it's multiple islands and Michigan with the lower and upper peninsula. The code breaks when you click on a group rather than an individual shape. I am not opposed to having separate macros for these two states but I cannot come up with a way that will work to change a group of shapes and cycle through them like "Case" does.

    Please Login or Register  to view this content.
    Map.JPG

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Fill Color for a Group of Shapes

    In my map, I set each state to a shape name and set two shapes in a group and tested with my code. I assigned Main() to run for each shape. A macro could be set to assign the macro to call for each shape if manually setting is too tedious.

    Would it be possible for you to attach the file or a simple obfuscated one?

    Click the Go Advanced button in lower right of a reply, and scroll past reply block and click Manage Attachments hyperlink and then Browse and Upload.

  5. #5
    Registered User
    Join Date
    08-27-2014
    Location
    Florida, U.S.
    MS-Off Ver
    2010
    Posts
    20

    Re: Fill Color for a Group of Shapes

    Thank you for telling me how to do it. I tried to attach the workbook to the last reply but I couldn't figure it out.
    Attached Files Attached Files

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Fill Color for a Group of Shapes

    Getting late so I will look at this tomorrow if not solved by then.

    I would solve it in 2 parts. Part 1 is done.

    1. Note the two added Ifs.
    Please Login or Register  to view this content.
    2. Looks like you will need to ungroup and regroup. e.g.
    Please Login or Register  to view this content.
    I would also recommend renaming the two groups to be more descriptive as in (2) and then modify (1). Note the use of Debug.Print. This puts a run's result into the Immediate window. This is one way to see the group name.

    This might make (2) more easy. https://msdn.microsoft.com/en-us/lib.../ff197890.aspx
    Last edited by Kenneth Hobson; 11-18-2016 at 01:34 AM.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Fill Color for a Group of Shapes

    This works for Michigan but not Hawaii. If you change Hawaii manually once, it works. If you look at the Debug results in the Immediate window after clicking Hawaii after it works once, it returns the wrong color.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-27-2014
    Location
    Florida, U.S.
    MS-Off Ver
    2010
    Posts
    20

    Re: Fill Color for a Group of Shapes

    Hi Kenneth,

    I didn't want you to think I forgot about you. Thank you for the time you spent helping me with this. My goal was to write this macro with as little to no help as possible. Obviously, that didn't work out too well when it comes to grouping shapes. Your code(s) you provided were awesome. In the end I wanted to stick with what I understood which was the code I had already written. In order to do so I had to give in to Excel a little and format some shapes differently. This has been a huge learning experience and I wanted to share the final product with you. Thanks again.
    Attached Files Attached Files

+ 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] Click oval option button to fill/unfill color, also change border color to match fill
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 08:29 PM
  2. [SOLVED] Changing fill color of shapes based on changing cell value
    By Stefan1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2012, 10:33 AM
  3. [SOLVED] How can I fill color in Group box (form control)
    By anand_erin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2012, 04:46 PM
  4. [SOLVED] Change color of text for a group of shapes
    By emiliekatherine in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2012, 08:43 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. Compare 2 worksheets, delete dupes and group by back fill color using macro
    By jousterlj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2011, 01:50 PM
  7. Color a shape of a group of shapes
    By lgiannetti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 09:18 AM

Tags for this Thread

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