I need to add a loop to my code for inserting a picture. Help please?

EvieLove

New Member
Joined
Feb 13, 2017
Messages
1
I have this code to insert a picture from a file based on the name of the file in the A2 it puts a picture into B2. it works perfectly but I need to be able to repeat this for all rows that have a number in column A. Sometimes very long lists. Can someone please help me with a loop for all rows with a number?

Thanks
Eve

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A2")) Is Nothing Then Exit Sub
Dim myPict As Picture


With Range("B2")
Set myPict = Range("B2").Parent.Pictures.Insert("I:\Presenter\Images\" & Target.Value & ".jpg")
myPict.Top = .Top
myPict.Width = .Width
myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With


End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
EvieLove,

Try Do Until ... Loop

Range("A2").activate /move to the top of the column
Do Until I=Range("A1048576").End(xlUp).Row / keep looping until you reach the last USED cell in column A

If Activecell.Value >0 then
With ActiveCell
Set myPict = ActiveCell.Offset(0,1).Parent.Pictures.Insert("I:\Presenter\Images" & Target.Value & ".jpg")
myPict.Top = .Top
myPict.Width = .Width
myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With


end if
I = I+1
Loop
 
Upvote 0

Forum statistics

Threads
1,215,396
Messages
6,124,685
Members
449,179
Latest member
kfhw720

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top