Changing the Color of Shapes based on Cell Values

Tevinaf

New Member
Joined
Apr 7, 2016
Messages
10
Hey Guys,

On an excel worksheet I have a group of different shapes. I want to find a way to change the color of each shape based on the cell values. example: I want shape 1 to change to blue if Cell D21 is the number 3, Shape 2 to change to say Green if Cell E21 is 4, etc.
I also want it to work automatically.
This is what I have so far, but it doesn't seem to work

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D21")) Is Nothing Then
        If IsNumeric(Target.Value) Then
            If Target.Value = 0 Then
                ActiveSheet.Shapes("Rectangle 6").Select
                Selection.ShapeRange.Fill.BackColor.RGB = RGB(238, 236, 225)
            ElseIf Target.Value = 1 Then
                ActiveSheet.Shapes(Array("Rectangle 6", "Group 73")).Fill.BackColor = RGB(146, 208, 80)
            ElseIf Target.Value = 2 Then
                ActiveSheet.Shapes("Rectangle 6").Fill.BackColor.RGB = vbRed
            ElseIf Target.Value = 3 Then
                ActiveSheet.Shapes("Rectangle 6").Fill.BackColor.RGB = RGB(0, 176, 240)
            ElseIf Target.Value = 4 Then
                ActiveSheet.Shapes("Rectangle 6").Fill.BackColor.RGB = RGB(218, 150, 148)
            ElseIf Target.Value = 5 Then
                ActiveSheet.Shapes("Rectangle 6").Fill.BackColor.RGB = RGB(191, 191, 191)
            ElseIf Target.Value = 6 Then
                ActiveSheet.Shapes("Rectangle 6").Fill.BackColor.RGB = RGB(255, 255, 0)
            End If
        End If
    End If
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
At the end of the sub I do have the End Sub line. Also I have 6 possible numbers assigned to a specific color.
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,111
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top