David said:
Could you please give example code?
First, insert some image in a worksheet and ensure it's named 'Picture 1'.
Copy the following code into the class module for the worksheet in which
'Picture 1' should appear when, e.g., cell A1 in that worksheet evaluates
to -1, but should not appear otherwise. This assumes cell A1 contains a
formula that would evaluate to -1, this triggerring the Calculate event
handler.
Option Explicit
Private Sub Worksheet_Calculate()
Static state As Boolean
On Error GoTo CleanUp
Application.EnableEvents = False
If (CDbl(Me.Range("A1").Value) = -1) <> state Then
Call TogglePic1
state = Not state
End If
CleanUp:
Application.EnableEvents = True
End Sub
Private Sub TogglePic1()
Dim x As Variant
With Me.Shapes("Picture 1")
.LockAspectRatio = msoFalse
x = Evaluate("Pic1H")
If IsError(x) Then
Me.Names.Add Name:="Pic1H", RefersTo:=.Height, Visible:=False
.Height = 0#
ElseIf .Height < 1# Then
.Height = x
Else
.Height = 0#
End If
x = Evaluate("Pic1W")
If IsError(x) Then
Me.Names.Add Name:="Pic1W", RefersTo:=.Width, Visible:=False
.Width = 0#
ElseIf .Width < 1# Then
.Width = x
Else
.Width = 0#
End If
End With
End Sub