Inserting a list of images based on cell value - using a command button - HELP PLEASE?

DBos92

New Member
Joined
May 17, 2018
Messages
2
Hi,

I am hoping someone can help on this. I know it's possible, i just don't know how...

Objective: To be able to insert a list of items, press a command button and then it pulls through the desired image.

Process
1. Insert the list of items into column A

2. Press a command button

3. In column b it pulls through an image based on the value of column A and re-sizes to fit cell

Thanks in advance!

Dan
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The below code
• loops through each cell in the selected range
• reads the filepath from that cell
• inserts the referenced picture in the cell to the right of the cell:
• resizes the height and width of the picture to the cell's height

Code:
Sub InsertPicFromFile()
Dim cCell As Range

For Each cCell In Selection
    If cCell.Value <> "" Then
        On Error Resume Next
        ActiveSheet.Shapes.AddPicture _
            Filename:=cCell.Value, LinkToFile:=msoFalse, _
            SaveWithDocument:=msoTrue, _
            Left:=cCell.Offset(ColumnOffset:=1).Left, Top:=cCell.Top, _
            Width:=cCell.Height, Height:=cCell.Height
    End If
Next cCell
End Sub

To use that code:
1)Select a vertical range of cells containing complete paths to picture
files.
(Make sure the row heights are large enough to view the pictures.)

2)Run the macro
• [Alt]+[F8]...to open the macro window
...Select: InsertPicFromFile
...Click [Run]

Is that something you can work with?
 
Upvote 0
Thanks Ron! Worked a treat!

I then managed to add a Command button/macro so I don't have to press Alt+F8 every time.

When the image is inserted is there a way of changing the size to a % of the original image? And inserting it into the center of the cell?

Thanks in advance!

Dan
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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