+ Reply to Thread
Results 1 to 6 of 6

Color a Shape the same color as a Cell - How?

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Color a Shape the same color as a Cell - How?

    Hi Everyone
    I have some cells (x 13) filled using Standard Colors determined originally from the Format, Fill color picker of the cell Conditional Formatting rules.
    Red, Amber (Orange), Green and a Grey.
    I have triangular (Auto)Shapes superimposed on the cells.
    How can I determine the exact color of each cell and apply it to fill the corresponding Shape?
    In this condition I don't want the triangle noticeable - but for aesthetics (ie for other conditions) I want the colors used to be consistent.
    All colors (both cells and shapes) will be determined by the contents of other cells.

    Can't say I yet understand the differences, pros and cons between Theme Colors, Scheme Colors, RGB colors, vb standard colors etc. Matching Amber/Orange is the troublesome one.

    With thanks
    barry
    Last edited by barryleajo; 12-14-2010 at 02:10 PM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Color a Shape the same color as a Cell - How?

    Hi barryleajo,

    why not just make the shape clear or

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim nIdx As Long
    Dim shp As Shape
    
        On Error GoTo errExit
        Set shp = Me.Shapes("xShape") ' < name to suit
        nIdx = Target(1).Interior.ColorIndex
        If nIdx < 1 Then nIdx = 58
        shp.Fill.ForeColor.SchemeColor = nIdx + 7
    
    errExit:
    
    End Sub
    http://www.ureader.com/msg/103768494.aspx
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

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

    Re: Color a Shape the same color as a Cell - How?

    Here is an example of the transparent shape approach Pike mentions.
    http://www.xldynamic.com/source/xld.CF.html#lights2
    Cheers
    Andy
    www.andypope.info

  4. #4
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Color a Shape the same color as a Cell - How?

    Many thanks Pike and Andy

    Pike

    ONE - yes using a "clear" shape sounds a really elegant solution but how do you do this. When I "fill" a cell with "No Fill" and use this to Fill the shape, it fills with White?
    TWO when I tried your code standalone it worked OK thank you.
    However when I embed it in mine - it keeps returning ColorIndex as -4142 (which I understand means no color?) irrespective of the actual cell color?
    THREE In have read that there are 56 colors available in a palette, why then 58 in your code?
    FOUR In the color picker there are 70 color swatches plus No colr - how does this stack with 56 (or 58)?

    Andy

    Thanks for the link and a useful approach.
    My shape sits on the coloured cell and this approach could work if I could set the shape to be transparent - see ablive.
    I didn't think Conditional Formatting could be used on Shapes?

    Finally, if I understand correctly the +7 in Pikes code (nIdx + 7) is to do with the different treatment of color indices by Excel 2007 from previous versions.
    If i settled on using RGB to deal with colors does this make the code anymore portable across different versions?

    I do understand if there are too many questions here!
    As ever many thanks though
    barry

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

    Re: Color a Shape the same color as a Cell - How?

    56 colours in xl2003. Not a limit in xl2007.

    The colour swatch in xl2007 uses 10 colours with variations (accents)

    To make your shape transparent you need to do the following.
    Copy the shape and Paste > As Picture > Paste as picture.
    The on the Picture Format contextual tab use the Format > Adjust > Recolor > Set transparent color.

  6. #6
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Color a Shape the same color as a Cell - How?

    OK Guys
    Very many thanks
    I have marked this as solved now - there is enough info for me to research/solve my problem.
    As ever, thank you
    barry

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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