making Images appear when conditions are satisfied

T

The Grinch

Hello All,

I have a sheet in which users are asked to enter data into a cell. Th
user is restricted to a small number of text entries. I have an imag
associated with each possible entry. Is there any way to make th
associated image appear on the sheet when the appropriate text i
entered into the cell?

Any help/comments would be appreciated
 
D

Dave Peterson

If you do some setup work, it can be pretty easy.

I put 5 pictures on a worksheet. I named them after what 5 values I want to
allow in A1.

Just rightclick on each picture (to select it) and then type the value in the
namebox (to the left of the formula bar.

Then right click on the worksheet tab that should have this behavior. Select
view code and paste this in the code window.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myPictNames As Variant
Dim iCtr As Long

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub

myPictNames = Array("car", "boat", "house", "street", "lawn")

On Error Resume Next
For iCtr = LBound(myPictNames) To UBound(myPictNames)
Me.Pictures(myPictNames(iCtr)).Visible = False
Next iCtr
Me.Pictures(Target.Value).Visible = True
On Error GoTo 0

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

And how are you limiting the choices for that cell? Via Data|Validation?

If yes and you're using xl97, this note from Debra Dalgleish's site may apply
http://www.contextures.com/xlDataVal08.html:

In Excel 97, selecting an item from a Data Validation dropdown list
does not trigger a Change event, unless the list items have been typed in
the Data Validation dialog box. In this version, you can add a button to
the worksheet, and run the code by clicking the button. To see an
example, go to the Sample Worksheets page, and under the Filters
heading, find Product List by Category, and download the
ProductsList97.xls file.
 
Top