+ Reply to Thread
Results 1 to 8 of 8

Change the Color of Shape in Excel Based on Cell Value using VBA

  1. #1
    Registered User
    Join Date
    06-10-2016
    Location
    Qatar
    MS-Off Ver
    2016
    Posts
    18

    Lightbulb Change the Color of Shape in Excel Based on Cell Value using VBA

    Hi Experts,

    Got VBA as below but Wanted to change command from Shipped, Delivered & On Hold to Done or Not Yet Done, Secondly is it possible to have VBA code for multiple cells for a single Shape like I'll be having A1 to A100 Done or Not Done if any of the Cell Shows Not Done Shape should turn to RED, if All Are Done Shape should be Green.


    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)

    ActiveSheet.Shapes("Rectangle 1").Fill.ForeColor.RGB = vbWhite

    If UCase(ActiveSheet.Cells(2, 1)) = "SHIPPED" Then
    ActiveSheet.Shapes("Rectangle 1").Fill.ForeColor.RGB = vbYellow
    End If

    If UCase(ActiveSheet.Cells(3, 1)) = "DELIVERED" Then
    ActiveSheet.Shapes("Rectangle 1").Fill.ForeColor.RGB = vbGreen
    End If

    If UCase(ActiveSheet.Cells(4, 1)) = "ON HOLD" Then
    ActiveSheet.Shapes("Rectangle 1").Fill.ForeColor.RGB = vbRed
    End If

    End Sub
    Regards,
    Kashif

  2. #2
    Registered User
    Join Date
    06-10-2016
    Location
    Qatar
    MS-Off Ver
    2016
    Posts
    18

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Anyone please 🥺

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  4. #4
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Please try this attachment.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-08-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    2

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Hi kskhan - does the following help at all. It uses conditional formatting to highlight the cells based on their values. It might need a bit of tidying up but seems to do the job.
    There's a second part (Clear_CF) which also removes the conditional formatting if you need to.

    CODE

    Sub colouring_in()
    '
    ' colouring_in Macro
    '


    Range("A1").Select 'change A1 to which ever cell your data starts in
    Range(Selection, Selection.End(xlDown)).Select
    ' Range(Selection, Selection.End(xlToRight)).Select

    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Done"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -0
    End With
    With Selection.FormatConditions(1).Interior
    .Color = 123458
    End With


    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Not Yet Done"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -0
    End With
    With Selection.FormatConditions(1).Interior
    .Color = 255
    End With



    Range("C1").Select 'change C1 to where ever you want the active cell to be after the formatting has been completed
    End Sub

    Sub Clear_CF()
    '
    ' Clear_CF Macro
    '

    '

    Range("A1", Selection.End(xlDown)).Select 'change A1 to which ever cell your data starts in
    ' Range(Selection, Selection.End(xlToRight)).Select
    Selection.FormatConditions.Delete

    Range("C1").Select 'change C1 to where ever you want the active cell to be after the removal of formatting has been completed
    End Sub

    /CODE

  6. #6
    Registered User
    Join Date
    06-10-2016
    Location
    Qatar
    MS-Off Ver
    2016
    Posts
    18

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Quote Originally Posted by HumphreyDog View Post
    Hi kskhan - does the following help at all. It uses conditional formatting to highlight the cells based on their values. It might need a bit of tidying up but seems to do the job.
    There's a second part (Clear_CF) which also removes the conditional formatting if you need to.

    CODE

    Sub colouring_in()
    '
    ' colouring_in Macro
    '


    Range("A1").Select 'change A1 to which ever cell your data starts in
    Range(Selection, Selection.End(xlDown)).Select
    ' Range(Selection, Selection.End(xlToRight)).Select

    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Done"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -0
    End With
    With Selection.FormatConditions(1).Interior
    .Color = 123458
    End With


    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Not Yet Done"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -0
    End With
    With Selection.FormatConditions(1).Interior
    .Color = 255
    End With



    Range("C1").Select 'change C1 to where ever you want the active cell to be after the formatting has been completed
    End Sub

    Sub Clear_CF()
    '
    ' Clear_CF Macro
    '

    '

    Range("A1", Selection.End(xlDown)).Select 'change A1 to which ever cell your data starts in
    ' Range(Selection, Selection.End(xlToRight)).Select
    Selection.FormatConditions.Delete

    Range("C1").Select 'change C1 to where ever you want the active cell to be after the removal of formatting has been completed
    End Sub

    /CODE
    Thanks alot Sir

  7. #7
    Registered User
    Join Date
    06-10-2016
    Location
    Qatar
    MS-Off Ver
    2016
    Posts
    18

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Quote Originally Posted by huuthang_bd View Post
    Please try this attachment.
    Thanks a lot Boss, Highly Appreciated

  8. #8
    Registered User
    Join Date
    06-10-2016
    Location
    Qatar
    MS-Off Ver
    2016
    Posts
    18

    Re: Change the Color of Shape in Excel Based on Cell Value using VBA

    Quote Originally Posted by Marc L View Post
    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Thanks a lot Boss, Appreciated.

+ 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 RGB based on Cells Color
    By jocker_boy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2019, 05:31 AM
  2. VBA change shape color based on cell value
    By noelmus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2018, 06:31 PM
  3. [SOLVED] Change the background color of a shape based on the value of a cell
    By domz3669 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-17-2018, 04:04 AM
  4. 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
  5. 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
  6. [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
  7. 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

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