Pic Macro

B

Brian Matlack

Hi!
How can I modify this code to work on any pic_ in the worksheet
(dozens) without having to enter each one individulally?
Anytime the active cell = the pic_"name" the picture appears.
When I select a name from a validation list in cell A1 I have to hit
enter in order for the correct picture to appear. Why?

<Start Code>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim shp As Shape
On Error GoTo ws_exit
Application.EnableEvents = False
Me.Shapes("pic_Kids").Visible = False
Me.Shapes("pic_Tractor").Visible = False
Me.Shapes("pic_Krause").Visible = False
If Target.Address = "$A$1" Then
Me.Shapes("pic_Kids").Visible = False
Me.Shapes("pic_Tractor").Visible = False
Me.Shapes("pic_Krause").Visible = False
End If
On Error Resume Next
Me.Shapes("pic_" & Target.Value).Visible = True
ws_exit:
Application.EnableEvents = True
On Error GoTo 0
End Sub
<End Code>

Any help would be appriciated!
Have a great holiday!!
 
G

Guest

Try something like this...

Dim shp As Shape

For Each shp In Shapes
shp.Visible = msoFalse
Next shp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top