How to display image as formula result

  • Thread starter Thread starter TerryG
  • Start date Start date
T

TerryG

I would like to display one of two images as the result of a formula,
something like:
if (A1=0, image1.gif, image2.gif)

But Excel does not deal with images like that. Any ideas how I could do
this?



------------------------------------------------
Message posted

-- View and post Excel related usenet messages directly from http://www.ExcelForum.com
at http://www.ExcelTip.com/
------------------------------------------------
 
I would like to display one of two images as the result of a formula,
something like:
if (A1=0, image1.gif, image2.gif)

But Excel does not deal with images like that. Any ideas how I could do
this?

You would need to use VBA code. You could use either the
Worksheet_Calculate event (triggered when the sheet is calculated), or
the Worksheet_Change event (triggered when a value changes). Let's say
that you go for calculate. Right click on the sheet's tab and select
"View Code". from the menu. That'll take you to the sheet's code
module. Now paste this in:

Private Sub Worksheet_Calculate()

'Avoid type mismatch errors.
If Not IsNumeric(Worksheets("Sheet1").Range("A1")) Then
Exit Sub
End If

With Worksheets("Sheet1")

If .Range("A1") = 0 Then
.Shapes("Picture 1").Visible = False
.Shapes("Picture 2").Visible = True
Else
.Shapes("Picture 1").Visible = True
.Shapes("Picture 2").Visible = False
End If

End With

End Sub

Change the names of the pictures to whatever yours are; you should see
that in the Name Box when you have the picture selected.
 
Back
Top