• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Add images macro skipping some random images to insert

I am running macro which allows user to select path where images are kept and then according to image names in "D" column, adds images in "A" column.
But this is skipping some rows like 12th and 18th one to insert images and so on. Images are present and their names are also correct in "D" column. Please help, thanks!
 

Attachments

  • InsertPictures.xlsm
    29.2 KB · Views: 5
Hello
I have tested your file and it is working well. I can't know the problem well
Can you upload the folder of images after compressing it to test it again to see the problem?
 
Hello
I have tested your file and it is working well. I can't know the problem well
Can you upload the folder of images after compressing it to test it again to see the problem?
If I manually run code using (F8), images are inserted correctly, I think for loop is not running correctly.
 
Also, following macro is running fine:
Code:
Sub InsertImageShortName()
   
    Application.ScreenUpdating = False

Dim pic As String ' File path of a picture
Dim cl As Range

Set Rng = Range("A1:A1974") ' Defining input range

For Each cl In Rng
   
    pic = "D:\1974_Final_Images_F\" & cl.Offset(0, 3) ' Location of the picture file:
                                    ' "C:\Images" folder, with particular image name
                                    ' Located in the same row, third column from A, i.e. column D

    Set myPicture = ActiveSheet.Pictures.Insert(pic) ' Inserting picture from address in D column
                                                    ' into column A
        With myPicture ' Setting picture properties
            .ShapeRange.LockAspectRatio = msoTrue ' Keep aspect ratio
            .Height = 150 ' Set your own size ' Column and row size: 37.09 and 157.5
            .Top = Rows(cl.Row).Top
            .Left = Columns(cl.Column).Left
        End With
    Next    ' Looping to the Nth row, defined in:
            ' " Set Rng = Range("A3:A10") "
   
    Set myPicture = Nothing
   
    Application.ScreenUpdating = True

End Sub

So as I am dynamically using image location and also not directly giving range for storing images, issue might be occuring in attached (posted question) code.
 
Back
Top