colour an picture based on a value

robjowens

Board Regular
Joined
Sep 26, 2009
Messages
102
Had a google and tried to use the recorder but haven't been able to find anything appropriate...

Any ideas on how I would be able to alter the colour of an picture based on a value in the cell, i.e. if cell B7 is between 1-10 it's blue, 11-20 green, 21+ yellow...

Any tips or reference points would be greatly appreciated.

cheers,
rob
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hello Rob,

I tried to insert a picture and color it but it barely did anything. I used a shape instead. Place this code in the worksheet module for which it will be used.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B7").Value = 0 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 1
Else
If Range("B7").Value = "" Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 1
Else
If Range("B7").Value > 0 And Range("B7") < 11 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 48
Else
If Range("B7").Value > 10 And Range("B7") < 21 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11
Else
If Range("B7").Value >= 21 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 13
End If
End If
End If
End If
End If
End Sub
If B7 is blank or 0 the shape will be white. You type in a number, move to another cell and the color should change.

If you know that the cell will always be 1 or greater you can use this instead:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B7").Value > 0 And Range("B7") < 11 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 48
Else
If Range("B7").Value > 10 And Range("B7") < 21 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11
Else
If Range("B7").Value >= 21 Then
ActiveSheet.Shapes("Oval 1").Fill.ForeColor.SchemeColor = 13
End If
End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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