Change color of an autoshape
Let me explain th eprocess to get this done. There are some tricks to get it
right.
First you need to record a macro to set the shape name. This is the easiest
way of getting the same name.
1) On worksheet go to Tools Menu - Macro - Record macro
2) select Shape and manually change the color.
3) Below is the macro I go doing these steps
' Macro recorded 9/20/2007 by Joel
'
'
ActiveSheet.Shapes("AutoShape 1").Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
End Sub
4) "AutoShape 1" is the name. 10 is the color for Red, 13 is yellow, 17 is
green
5) To get the color to change automatically need you need a worksheet change
function as I shown below. You need tto modify the code below by putting in
the shape name from the macro that was learned above. Also you need to
change the cell address in the following line of code "$B$7" is cell B7. One
trick that most people don't know is the learned macro had ShapeRange that I
had to remove to get my worksheet_change function to run without errors.
If target.Address = "$B$7" Then
Sub worksheet_change(ByVal target As Range)
If target.Address = "$B$7" Then
If target < 0.8 Then
ActiveSheet.Shapes("AutoShape 1"). _
Fill.ForeColor.SchemeColor = 10
End If
If (target = 0.8) And (target <= 0.9) Then
ActiveSheet.Shapes("AutoShape 1"). _
Fill.ForeColor.SchemeColor = 13
End If
If target 0.9 Then
ActiveSheet.Shapes("AutoShape 1"). _
Fill.ForeColor.SchemeColor = 17
End If
End If
End Sub
"Ly" wrote:
I am using Excel 2003 for my project and I have to set color of an autoshape
in column C based on the value in column B. For example:
*If the value in column B < 80%, a little square in column C must be Red
*If the value in column B is from 80% to 89%, a little square in column C
must be Yellow.
*If the value in column B 90%, a little square in C must be Green.
I've tried Conditional format, but it didn't work. Can someone help me
please.
Any help is appreciate.
|