Displaying Multiple Images based on Cell Value

hipster318

New Member
Joined
Apr 17, 2009
Messages
1
Hello,

Newbie here (as well as to VBA). Went to http://www.mcgimpsey.com/excel/lookuppics.html , which works great when only wanting to display one image on the worksheet (based on a cell value). However, what if I wanted to display multiple images based on this cell value? Not sure how to change the original code.

Private Sub Worksheet_Calculate()
Dim oPic As Picture
Me.Pictures.Visible = False
With Range("F1")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With
End Sub

For example, what if I also wanted to display a different image in cell "H1"? :confused:
Any help would be appreciated.
THanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try the following - I used the same named Range "pictable" as the example link you provided, just extended it such that H11 (your Example) for a second Image also looked up against that table for another picture name.

<code>

Private Sub Worksheet_Calculate()
Dim oPic As Picture
Dim oPic2 As Picture

Me.Pictures.Visible = False
With Range("E45")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With

With Range("H11")
For Each oPic2 In Me.Pictures
If oPic2.Name = .Text Then
oPic2.Visible = True
oPic2.Top = .Top
oPic2.Left = .Left
Exit For
End If
Next oPic2

End With

End Sub

</code>
 
Upvote 0

Forum statistics

Threads
1,216,022
Messages
6,128,325
Members
449,440
Latest member
Gillian McGovern

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top