Conditional Format A Shape

rockyw

Well-known Member
Joined
Dec 26, 2010
Messages
1,196
Office Version
  1. 2010
Platform
  1. Windows
I'm tying to change a shape based on a cell value. I have this but it will not change fron green to red.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     
    If Range("A100").Value >= 0 And Range("A100").Value <= Range("A100").Value Then
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbGreen
    ElseIf Range("A100").Value > Range("A100").Value Then
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbRed
    End If
     
End Sub

I would like the shape to go red, yellow and green but I can't find anything that works. Any help would be great. Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Your first "If" statement will always be true, If A100 equals itself is always true.
Your "Elseif" statement will never be true, If A100 is greater than itself is never true.

Not exactly sure what you are trying to do or what values you expect in "A100" but maybe "Select Case" will help.

Here's a sample:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     
Select Case Range("A100").Value

    Case 0 To 100
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbGreen
    Case 101, 102, 103, 110 To 125
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbRed
    Case 104 To 109, 126 To 200
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbYellow
    Case Else
        ActiveSheet.Shapes("Oval 5").Fill.ForeColor.RGB = vbBlue
        
End Select
     
End Sub

Hope it helps,

Gary
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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