Insert picture based on cell value

NIHSCTEST

New Member
Joined
Sep 8, 2015
Messages
3
hello,
I hope to find some help here as I would really like to find an easier way than just insert each picture manually. I have range of cells value which I need to add pictures for (hundred of cells values). For this example cell values:
B1: Desert
B2: Jellyfish
B3: Koala

I'm looking to insert image so these values into column A. If there is no pictures then text "No picture found" should appear. Someone wrote VBA which I modified slightly but pictures are not showing.

Sub Load_Picture()


Dim Entry As Range
Dim WorkArea As Range
Dim Source As Worksheet


With Application
.ScreenUpdating = False
End With


Set Source = Sheets("Sheet1")
Set WorkArea = Source.Range(Cells(2, 2), Cells(Cells(Rows.Count, 2).End(xlUp).Row, 2))


For Each Entry In WorkArea
PicturePath = Dir("C:\Users\Public\Pictures\Sample Pictures" & ".jpg")
If PicturePath <> "" Then
Set Shp = ActiveSheet.Shapes.AddPicture(Filename:="C:\Users\Public\Pictures\Sample Pictures" & ".jpg" _
, LinkToFile:=False, SaveWithDocument:=True, Left:=Cells(Entry.Row, 1).Left, Top:=Cells(Entry.Row, 1).Top _
, Width:=Cells(Entry.Row, 1).Width, Height:=Cells(Entry.Row, 1).Height)
Shp.Placement = xlMoveAndSize
Shp.ControlFormat.PrintObject = True
Else
Entry.Offset(0, -1).Value = "Picture Not Found"
End If
Next Entry




End Sub
_______________________________

VBA does seem to work because it places "Pictures Not Found" in the column A for all B1-B3 values. But how to get the actual pictures in Column A? Is there something missing in the VBA?

Thank you for your help.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I tested the code and it worked. Two problems I see are a) it always inserts the same picture, regardless the cell value, and b) it scales the picture to the cell, thus, distorted picture.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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