Insert picture in Excel: cell, shortcut, using formula

Insert picture in Excel: cell, shortcut, using formula

Macros in Excel can perform functions like inserting pictures, copying data from one cell to another, etc. In order to write an effective macro to insert images in excel, you will need to use a loop. This FAQ will walk you through the steps to applying this macro to your spreadsheet in order to have pictures appear.

How to use a macro formula to insert pictures in Excel?

In order to use a macro to insert pictures, you must begin with the following assumptions: picture names are found in col B starting at B2; you want to paste each picture at different location; where to paste the picture identified in col B is found in col C starting at C2.

Now, enter the following code:

Sub Picture()   
 Dim picname As String   
Dim pasteAt As Integer   
 Dim lThisRow As Long   
lThisRow = 2   
Do While (Cells(lThisRow, 2) <> "")   
'Range("A6").Select 'This is where picture will be inserted   
        pasteAt = Cells(lThisRow, 3)   
        Cells(pasteAt, 1).Select 'This is where picture will be inserted   
'Dim picname As String   
        'picname = Range("B6") 'This is the picture name   
         picname = Cells(lThisRow, 2) 'This is the picture name   
ActiveSheet.Pictures.Insert("C:\Users\vbayat\My Documents\vidabayat\re-market\" & picname & ".jpg").Select 'Path to where pictures are stored   
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''   
        ' This resizes the picture   
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''   
        With Selection   
            '.Left = Range("A6").Left   
            '.Top = Range("A6").Top   
            .Left = Cells(pasteAt, 1).Left   
            .Top = Cells(pasteAt, 1).Top   
.ShapeRange.LockAspectRatio = msoFalse   
            .ShapeRange.Height = 100#   
            .ShapeRange.Width = 80#   
            .ShapeRange.Rotation = 0#   
        End With   
lThisRow = lThisRow + 1   
Loop   
Range("A10").Select   
    Application.ScreenUpdating = True   
Exit Sub   
ErrNoPhoto:   
    MsgBox "Unable to Find Photo" 'Shows message box if picture not found   
    Exit Sub   
    Range("B20").Select   
End Sub

Is there a shortcut to enter a picture in Excel?

Yes, you can use the insert picture button at the top of the page. You will be directed to find the picture you want to insert from your computer. 

If you already have the picture you want to insert on your clipboard, you can press CTRL + V to paste the image. 

Need more help with Excel? Check out our forum!
Around the same subject

Excel