Excel VBA: Insert Picture from Directory on Cell Value Change

Please login in order to report media.

  • Uploaded 9 months ago in the category How to programming

    Insert a picture from the directory on the change of a cell value using Excel VBA.

    In this video tutorial when someone changes the value of cell A2, a picture is automatically inserted from a folder in the directory.

    The cell is also automatically resized to be the same as the picture.

    Learn Excel VBA Fast with our highly rated online course - https://www.udemy.com/excel-vba-course/?couponCode=ExcelVBAYouTube

    This macro can be placed in a sub procedure and does not need to run on the worksheet change event.

    It could also be used in a loop to insert multiple pictures from that directory.

    Below is the code used in the video.

    This can be copied and adapted for your own needs.

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim myPict As Picture
    Dim PictureLoc As String

    If Target.Address = Range("A2").Address Then


    PictureLoc = "C:UsersAdminDesktopimages" & Range("A2").Value & ".png"

    With Range("B2")
    Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
    .RowHeight = myPict.Height
    myPict.Top = .Top
    myPict.Left = .Left
    myPict.Placement = xlMoveAndSize
    End With

    End If

    End Sub

    Find more great free tutorials at;

    Connect with us!
    Google+ ► https://plus.google.com/+Computergaga
    Facebook ► http://www.facebook.com/computergaga
    Twitter ► http://www.twitter.com/computergaga1

  • excelvba:insertpicturedirectorycellvaluechange