VBA to Insert Pictures into the Cell based on the value in another coln.


New Member
Mar 1, 2012
Hey guys

Can someone please help me fix up my VBA code ? :'(

Here is my current code:

Sub PlacePics()    Dim Path As String, Pics As Range, Pic As Range, Pix As Picture
    On Error Resume Next
    Path = "C:\Users\Panda\Pictures\"
    Set Pics = ActiveSheet.Range("A9:A504")
    For Each Pic In Pics
        Pic.Offset(0, 1).Select
        Set Pix = ActiveSheet.Pictures.Insert(Path & Pic.Value & ".jpg").Select
        With Pic
            .ShapeRange.LockAspectRatio = msoFalse
            .Left = ImageCell.Left
            .Top = ImageCell.Top
            .Width = ImageCell.Width
            .Height = ImageCell.Height
        End With
    Next Pic
End Sub
Basically I would like to insert jpg images into coln B from a folder. The names of the pictures are based in the text values in coln A.

That is currently working however I would like to make 2 improvements.

Improvement 1 is if the image doesn't exist skip it. (At the moment I have the resume next but I hear this isn't good coding)

Improvement 2 which is the main issue:

The images are different sizes some are way too big. I would like to insert it into the cell and make the height of the cell be the limiting factor and scale it to scale (aspect ratio)?

Can someone please help?

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...