+ Reply to Thread
Results 1 to 7 of 7

Changing shape and font colour based on text

  1. #1
    Registered User
    Join Date
    10-06-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    16

    Changing shape and font colour based on text

    Hello people!

    I have some shapes with text linked to certain cells. When the cell value is "R", I want the shape colour and the text inside the shape colour to be red. The same with B for blue and G for green. I have attached an example. I need a script that runs through the shapes in the sheet and changes the shape and font colour accordingly. I have tried a few times, but couldn't come up with a solution.

    When I try to Dim Shp As Shape, I get an error at the For Each Shp in Sheets("...").Shapes . It seems that no shape is found.

    Can anyone help me with a solution?

    Thank you
    !
    Attached Files Attached Files

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Changing shape and font colour based on text

    This code seems to loop through all you Shapes in the worksheet and select them.

    Please Login or Register  to view this content.
    re your not working code try to add after the line "For Each ....


    Please Login or Register  to view this content.
    Alf

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing shape and font colour based on text

    Your shapes are grouped, so you need to deal with groupitems of each shape.

    Try this - tweak the RGB values to match your requirement:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  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: Changing shape and font colour based on text

    I guess you were wanting to hide the text in the shapes? If so, this will work. Put it before the last End Sub in Olly's post #3.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-06-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    16

    Re: Changing shape and font colour based on text

    Thanks, guys!

    I've tried Olly's approach and I get a "Method 'Range' of object '_Worksheet' failed" error. at this line:
    Please Login or Register  to view this content.
    I can't really read through the logic of your code Olly, so can you help me fix this error? It colours one triangle and then I get the error.

    Thanks a lot!

    I don't need to have the objects grouped. It's not necessary. I just did that to keep the triangles all together, but I can ungroup them if that helps.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing shape and font colour based on text

    I can't recreate that error, with the workbook you attached, but I can see that may happen if a shape doesn't have a formula which refers to a cell. I also spotted a small error in the code...

    Try this (changes in red):

    Please Login or Register  to view this content.
    This will work with grouped or ungrouped shapes.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-06-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    16

    Re: Changing shape and font colour based on text

    Thanks Olly! It works.

    There's one minor tweak I need to do. I will add some textboxes as well, so I would need it to skip those shape types (type 17, I believe) and only colour the shape and text of the triangles (type 5, I think). How do I insert that condition into the logic?

    Cheers!

+ 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] Count Based on Text and Font colour
    By SamFitz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-02-2016, 12:39 PM
  2. Changing font colour based on a character
    By pjzapped in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 03-27-2016, 07:02 AM
  3. Replies: 1
    Last Post: 01-02-2015, 09:18 AM
  4. Getting Colour wise totals by changing font colour
    By Anuru in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-24-2014, 11:13 AM
  5. Macros assigned Shape, colour changing code needed please
    By lcartwright in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2014, 05:36 AM
  6. [SOLVED] Changing Shape colour by a click?
    By [email protected] in forum Excel General
    Replies: 4
    Last Post: 10-27-2005, 05:05 AM
  7. Changing the Colour of an Auto Shape (Line)
    By d.i.barr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-23-2005, 05:48 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