Jasen79
New Member
- Joined
- Nov 25, 2020
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
- MacOS
Below is a code I had a lot of help with from user such as yourself.
This code worked well but now is stopping a row 10 and I can't see why!
Could one of you please be so kind to point out why this is happening and how I might fix it?
What should be happen in short is and does up to row 10, is the code will like at a cell, see if there is a xxx.jpg name, if there is then it looks it up in a folder from on the PC, and insert the picture, then loops on to the next row and cell.
Thank you for your help and insight.
This code worked well but now is stopping a row 10 and I can't see why!
Could one of you please be so kind to point out why this is happening and how I might fix it?
What should be happen in short is and does up to row 10, is the code will like at a cell, see if there is a xxx.jpg name, if there is then it looks it up in a folder from on the PC, and insert the picture, then loops on to the next row and cell.
Thank you for your help and insight.
Code:
Sub Pic_insert()
Dim last_row As Long
Dim cell As Range
Dim col_num As Long
Dim j As Long, i As Long
last_row = Sheets(1).Range("I654").End(xlUp).Row
Do While Sheets(1).Cells(last_row, 9) = 0
last_row = last_row - 1
Loop
For j = 2 To last_row Step 1
For i = 9 To 11 Step 1
InsertirPictures Cells(j, i)
Next i
Next j
End Sub
Sub InsertirPictures(cel As Range)
' Help from YKY & RoryA
' Personal Note: Below file path needs to be changed to where the IR photos are located!!!
'
Const fPath = "C:\Users\576186\Pictures\"
Dim picPath As String
picPath = fPath & cel.Value
If Not Dir(picPath, vbDirectory) = vbNullString Then
cel.Worksheet.Shapes.AddPicture Filename:=picPath, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Top:=cel.Offset(, 0).Top, Left:=cel.Offset(, 0).Left, Width:=125, Height:=125
End If
End Sub