Call photo from range, please help

Akbaru

New Member
Joined
Oct 28, 2015
Messages
32
Hello community,

I have a vba code which shows specific photo when you choose name from Data Validation list (car names, shows car photos)
But it shows only 1 photo , can anybody help me to make it 4 photo instead of 1?

Data Validation = OFFSET to image table

VBA:

Code:
Private Sub Worksheet_Calculate()
Dim oPic As Picture
Me.Pictures.Visible = False
With Range("j1")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
oPic.Height = 250
oPic.Width = 250
Exit For
End If
Next oPic
End With
End Sub~[/CODE
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
It's not clear what you're asking for. If you want to display 4 photos at the same time, then you would have to repeat the lines of code starting with oPic.Visible = True in a suitable way. A vague answer (and I might have misunderstood your requirement) to a vague question.
 
Upvote 0
What are the names of the pictures? Say the Data Validation choices are Car1 and Car2, and the 4 pictures for Car1 are named Car1_1, Car1_2, Car1_3, Car1_4, and the 4 pictures for Car2 are named Car2_1, Car2_2, Car2_3, Car2_4, the following code will display all 4 pictures for the chosen car, one below the other starting at cell K2.

Code:
Private Sub Worksheet_Calculate()
    Dim oPic As Picture, pictureCell As Range, i As Integer
    
    Me.Pictures.Visible = False
    Set pictureCell = Range("K2")
    For Each oPic In Me.Pictures
        For i = 1 To 4
            If oPic.Name = Range("J1").Text & "_" & i Then
                oPic.Visible = True
                oPic.Top = pictureCell.Top
                oPic.Left = pictureCell.Left
                oPic.Height = 100
                oPic.Width = 100
                Set pictureCell = pictureCell.Offset(oPic.BottomRightCell.Row - oPic.TopLeftCell.Row + 1, 0)
            End If
        Next
    Next oPic
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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