ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically insert a graphic? (https://www.excelbanter.com/excel-programming/394061-programmatically-insert-graphic.html)

Kent McPherson[_2_]

Programmatically insert a graphic?
 
I have a spreadsheet where I want to create a traffic light view of the
data. For example:

Value 1-3 = red circle
Value 4-6 = yellow circle
Value 7-10 = green circle

The formula I'm working with looks like this:

=IF(Sheet1!B2<4,red,IF(Sheet1!B2<7,yellow,green))

The red, yellow, and green items need to pull graphic symbols which is where
I'm struggling. How can I do that?



Anony

Programmatically insert a graphic?
 
Here's just an idea of a VBA module that could do the work for you:

Sub Circles()

Sheets("Sheet1").Activate
Select Case ActiveSheet.Range("B2")
Case Is = 7
'Change 20, 20, 50, 50 to adjust the size and location of the circles
ActiveSheet.Shapes.AddShape(msoShapeOval, 20, 20, 50, 50).Select
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11
Selection.ShapeRange.Line.Visible = msoFalse
Case Is = 4
ActiveSheet.Shapes.AddShape(msoShapeOval, 20, 20, 50, 50).Select
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 5
Selection.ShapeRange.Line.Visible = msoFalse
Case Else
ActiveSheet.Shapes.AddShape(msoShapeOval, 20, 20, 50, 50).Select
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10
Selection.ShapeRange.Line.Visible = msoFalse
End Select

End Sub


--------
Cheers,
Anony


"Kent McPherson" wrote:

I have a spreadsheet where I want to create a traffic light view of the
data. For example:

Value 1-3 = red circle
Value 4-6 = yellow circle
Value 7-10 = green circle

The formula I'm working with looks like this:

=IF(Sheet1!B2<4,red,IF(Sheet1!B2<7,yellow,green))

The red, yellow, and green items need to pull graphic symbols which is where
I'm struggling. How can I do that?





All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com