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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

brian5857

Board Regular
Joined
Jan 28, 2005
Messages
64
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

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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,190,558
Messages
5,981,688
Members
439,730
Latest member
gjvv

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