Colour an object based on cell content

JonesyUK

Board Regular
Joined
Oct 11, 2005
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi - Thanks for your advice.

I have a circle object on an Excel spreadsheet(I used "Insert", "Shapes" to put it there).

I would like to change the colour of the circle object based on the contents of cell A1.

Cell A1 will be "Red", "Yellow" or "Green".

If I type "Green" into cell A1, then I would like the circle object to change to green.
If I type "Yellow" into cell A1, then I would like the circle object to change to yellow....

etc. etc.

Hope this makes sense, and again, thanks for your response.
C
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You would need to use the Worksheet_Change event procedure to do that. The macro recorder will get you started, but post back if you are still stuck.
 
Upvote 0
Hi Andrew - sorry, but you lost me with "use the Worksheet_Change event"...

Maybe list all the steps? I am using Excel 2007.

Thanks.
C
 
Upvote 0
Right click the worksheet tab and choose View Code. Paste this into the window on the right:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$A$1" Then Exit Sub
    With Shapes("Oval 1").Fill
        Select Case Target.Value
            Case "Red"
                .Visible = msoTrue
                .ForeColor.SchemeColor = 10
            Case "Yellow"
                .Visible = msoTrue
                .ForeColor.SchemeColor = 13
            Case "Green"
                .Visible = msoTrue
                .ForeColor.SchemeColor = 17
            Case Else
                .Visible = msoFalse
        End Select
    End With
End Sub

The code assumes your circle is named "Oval 1" - change to suit. Close the Vsual Basic Editor and try it out.
 
Upvote 0
Hi Andrew, it works like a dream!

Thanks a million for the quick response.

Clint
 
Upvote 0
Okay, this worked great, but I should probably have explained the entire exercise:

I have about 50 graphs on the sheet called "LINE_PPT". Each graph will have an object(a little circle) placed on it like a little traffic light indicator, which should change colour based on the value assigned to it. The values are on the sheet called "TREND".

So on Sheet = "TREND", I have the following data:

"Col M" "Col N"
Oval 1 30
Oval 2 20
Oval 3 10
Oval 4 30
Oval 5 10
Oval 6 10
Oval 7 10
Oval 8 30
Oval 9 30
Oval 10 10
Oval 11 20
Oval 12 10
Oval 13 10
Oval 14 30
Oval 15 10
Oval 16 30
Oval 17 10

etc. etc. all the way to Oval 50...

How do I change this macro so that the target cell $A$1 becomes

SHEET NAME = "TREND"
CELL = "M4" which is oval 1

And loops through all the objects, changing their colours...

Hope this makes sense...

Thanks as always,
C
 
Upvote 0
Hi Andrew, the colour is determined by a number 10, 20, or 30.

So on the sheet named "Trend", cells M4 to M20+ will have the oval name and the value which determines the colour:

10 20 30
Green Red Amber

Oval 1 = 30
Oval 2 = 20
Oval 3 = 10 etc. etc...

Thanks...
Clint
 
Upvote 0
Also, these are the colours I'm using:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub
With Shapes("Oval 1").Fill
Select Case Target.Value
Case 30
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
Case 20
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 192, 0)
Case 10
.Visible = msoTrue
.ForeColor.RGB = RGB(146, 208, 80)
Case Else
.Visible = msoFalse
End Select
End With
End Sub
 
Upvote 0
Try (in the Module for the TREND worksheet):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Application.Intersect(Target, Range("N4:N53")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    With Shapes(Target.Offset(, -1).Value).Fill
        Select Case Target.Value
            Case 30
                .Visible = msoTrue
                .ForeColor.RGB = RGB(255, 0, 0)
            Case 20
                .Visible = msoTrue
                .ForeColor.RGB = RGB(255, 192, 0)
            Case 10
                .Visible = msoTrue
                .ForeColor.RGB = RGB(146, 208, 80)
            Case Else
                .Visible = msoFalse
        End Select
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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