I would like to insert a picture in Excel from a file depending on a cell value.
I have a set of pictures in a file, each with a different name.
In Excel, I have a table that is populated with a list of names, depending on certain criteria. The list is a group of words that are the same as the picture’s names.
Is there a way through which I can upload the pictures to Excel, when the picture name appears in the list?
Consider this methodology.
Sub InsertPics() Dim fPath As String, fName As String Dim r As Range, rng As Range Application.ScreenUpdating = False fPath = "C:/Users/Public/Pictures/Sample Pictures/" Set rng = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row) i = 1 For Each r In rng fName = Dir(fPath) Do While fName <> "" If fName = r.Value Then With ActiveSheet.Pictures.Insert(fPath & fName) .ShapeRange.LockAspectRatio = msoTrue Set px = .ShapeRange If .ShapeRange.Width > Rows(i).Columns(2).Width Then .ShapeRange.Width = Columns(2).Width With Cells(i, 2) px.Top = .Top px.Left = .Left .RowHeight = px.Height End With End With End If fName = Dir Loop i = i + 1 Next r Application.ScreenUpdating = True End Sub ' Note: you need the file extension, such as ',jpg', or whatever you are using, so you can match on that.