Conditional Format A Shape

rockyw

Well-known Member
Joined
Dec 26, 2010
Messages
1,191
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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Gary McMaster

Well-known Member
Joined
Feb 8, 2009
Messages
1,977
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
 

Forum statistics

Threads
1,137,060
Messages
5,679,380
Members
419,824
Latest member
Mercy kiara

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
Top