Add a picture to a cell that only appears on click

  • Thread starter Thread starter mikef255
  • Start date Start date
M

mikef255

I want to add a picture to a cell that will appear when the user clicks on
the "picture" cell. For example, a list of parts, that shows the picture of
the part when it is clicked on.
 
I assume you have already named your pictures as the part number as in th
"picture cells"

Try the following in the sheet module (rt-click sheet tab, view code).
Change C3:C11 to the range of your picture cells, a named range perhaps.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim pic As Picture
On Error GoTo errExit
Me.Pictures.Visible = False
If Not Intersect(Range("C3:C11"), Target(1)) Is Nothing Then
Set pic = Me.Rectangles(Target(1).Value)
If Not pic Is Nothing Then
With Target(1)
pic.Left = .Left + .Width - 2
pic.Top = .Top + 2
pic.Visible = True
End With
End If
End If
errExit:
End Sub

Regards,
Peter T
 
Peter T said:
I assume you have already named your pictures as the part number as in th
"picture cells"

Try the following in the sheet module (rt-click sheet tab, view code).
Change C3:C11 to the range of your picture cells, a named range perhaps.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim pic As Picture
On Error GoTo errExit
Me.Pictures.Visible = False
If Not Intersect(Range("C3:C11"), Target(1)) Is Nothing Then
Set pic = Me.Rectangles(Target(1).Value)
If Not pic Is Nothing Then
With Target(1)
pic.Left = .Left + .Width - 2
pic.Top = .Top + 2
pic.Visible = True
End With
End If
End If
errExit:
End Sub

Regards,
Peter T






Thanks Peter, That worked perfect!!!
 

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

Back
Top