Autoshape color

brian5857

Board Regular
Joined
Jan 28, 2005
Messages
64
I have an autoshape that is an oval (Oval 10). Cell A1 will either have a value of 1 or zero.

Does anyone know VB code that will change the fill color of the oval depending on the value of cell A1?

0=red

1=green
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
If A1 is being changed manually try this. Right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A1" Then
    Select Case Target.Value
        Case 0: Me.DrawingObjects("Oval 10").Interior.ColorIndex = 3
        Case 1: Me.DrawingObjects("Oval 10").Interior.ColorIndex = 10
    End Select
End If
End Sub
 
Upvote 0
Thanks for the help! That worked good if I manually type in 0 or 1 and then press enter. But it doesnt work in my sheet because the value in cell A1 is changing on its own. The cell has a formula in it that looks at a bit in a PLC and shows if the bit is a 1 or a 0.
 
Upvote 0
Try this instead

Code:
Private Sub Worksheet_Calculate()
Select Case Range("A1").Value
    Case 0: Me.DrawingObjects("Oval 10").Interior.ColorIndex = 3
    Case 1: Me.DrawingObjects("Oval 10").Interior.ColorIndex = 10
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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