Ace My Paper - get your Excel tasks done by experts. - makes your homework shine.


Excel tutorials

Insert and Resize Picture from Folder to Selected Cell

Adding an Image or Picture to an Excel Merged Cell and Automatically Adjust the Size

In this tutorial I will show how we can Insert an Image or Picture into a Selected Cell (merged cell) from a Folder on our hard drive. This insert images from a folder in a specific cell is performed using a VBA macro attached to this tutorial.

I would like to mention that this VBA macro attached, inserting a picture in a selected cell consisting of two merged cells in a way to adjust the image height Excel Merged Cells and the width is automatically adjusted.
For example: If one and the same image are put into the three cells of different heights (Row High) image will either reduce or increase to adjust the height of the selected cells.

In the picture below you see the situation and the cells in which we need to display, add or import images from a folder with our hard drive that we choose through the dialog 'Select image to insert' after running VBA macros. You notice that the three cells of different sizes, these cells are were merged.


Thus we have the following merged cell B3='B3:C3' ; B5='B5:C5' ; B7='B7:E7'. In these cells we need to add images that will select the folders on the disc. Each added (inserted) Image or Picture will be adjusted to the size of the cells that are selected by before launching a VBA macro.

Inserting image from a folder in a selected merged cells

This complete VBA macro below You copy it into 'Sheet Module' your Workbook (You must, be sure to save the workbook '*.xlsm' or '*.xls' format.

Copy VBA macro to VBE and Create Button to run VBA

ie. Launch VBA macro (or run through ALT+F8) on the same worksheet (the active worksheet) and try to insert images from a folder on your hard drive.

Sub InsertImageFromFolder()
Dim myPicture As String, myRange As Range 'set of variables for the image and a selected cell
'defining image formats for import
myPicture = Application.GetOpenFilename _
("Pictures (.gif; .jpg; .bmp; .tif),.gif; .jpg; .bmp; .tif", _
, "Choose image for insert")
Set myRange = Selection 'defining the selected cells
'Set myRange = Application.InputBox("Select your range...", Type:=8) 'message to select the destination cell - option
InsertAndSizePic myRange, myPicture 'calling the procedure for resizing images
End Sub

Sub InsertAndSizePic(Target As Range, PicPath As String)
'procedure to insert a picture and adjust the size of the destination cell

Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top
p.Left = .Left
p.Width = .Width
p.Height = .Height
End With
End Sub

After copying the VBA macros and create a button to run the same, let's try the functioning of the VBA macro. (inspiration for the tutorial and VBA source code:

Insert and Display Image or Picture from Folder to a selected Excel Cell

  • Select the cell B3
  • Click on the button to run a VBA macro or use the shortcut ALT+F8
  • The newly opened dialog box, locate the folder where select image
  • Click on the OK button
  • Now to the previously selected cell, you should have inserted an image that fit the size or dimensions of the selected cell. So in some cells of the image is reduced in some cells of the image is increased.
  • All this repeat for each additional Excel cell

In my case it looks like the image below, you notice that the picture of the Croatian flag accommodate the dimensions and size of each cell and its real dimensions are 50x33 pix.

How to insert or add a picture from a folder or folders in a single cell or merged cells in Excel to make the image fit the size of the cell

Aslo, You can see related tutorials:

- Automatically display Image or Picture based on Value in Adjacent Cell
- Display Picture from another Worksheet based on Name or Value in Adjacent Cell