MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Insert Graphics in Cell by condition

Posted by Craig D on January 27, 2002 6:39 AM

Does any one know how to insert a graphic into a cell
based upon the value of a cell. Kind of like conditional formatting but instead of coloring the cell
I'd like it to insert a graphic.


Posted by Dan Aragon on January 27, 2002 10:56 AM

You would need to do this with VBA. You could add a macro that tests the value of the cell and inserts the picture if the value meets the criteria. A basic example would be the following. Assuming that your are testing cell A1, you would add this code to the worksheet you want this to happen in:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$1" Then
If Target.Value > 10 Then
Target.Offset(1, 0).Select
End If
End If
End Sub

This puts picture.bmp in to cell A1 if the value of A1 is greater than 10. What this doesn't have is code to remove the picture if the cell is changed to something less than 10, but hopefully this will get you started. If you need more help, you can email me or reply back.