Excel macro loop to insert pics into more cel [Solved/Closed]

Report
Posts
5
Registration date
Thursday February 18, 2010
Status
Member
Last seen
February 19, 2010
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hello,
Could someone please help me in writing a loop in this macro in excel :
I have an excel sheet where it contains the name of the pictures in column B. I have written a Macro to pick up the name of the picture in column B and insert the actual picture from directory into column A.
I need create a loop to do this depending on the number of pictures in the column B. The number of rows varies from 10 to 1000.
The macro that I have written works perfect for the first row but does not go to the next row since I am not sure how to do it.
Thanks for your help in advance.
vba
Please see the macro that I’ve written:-

Sub Picture()
Range("A6").Select 'This is where picture will be inserted
Dim picname As String
picname = Range("B6") '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
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 100#
.ShapeRange.Width = 80#
.ShapeRange.Rotation = 0#
End With

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

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
2
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!