Hi Everybody,
Can I ask you help with the following VBA code?
It works fine. However when the formula find an empty cell it stops. I would like it to keep on going despite the empty cells here and there and stop when the are no more cells with text.
Thank you for you help
Sub Picture()
Dim pictname As String
Dim pastehere As Range
Dim pasterow As Long
Dim x As Long
Dim lastrow As Long, cPic
lastrow = Worksheets("sheet1").Range("B1").CurrentRegion.Rows.Count
x = 2
For x = 2 To lastrow
Set pastehere = Cells(x, 1)
pasterow = pastehere.Row
Cells(pasterow, 1).Select 'This is where picture will be inserted
pictname = Cells(x, 2) 'This is the picture name
Set cPic = ActiveSheet.Shapes.AddPicture("C:\Users\90009672\Desktop\baba\" & pictname & ".jpg", False, True, PosizLeft, PositTop, True, True)
' ActiveSheet.Pictures.Insert("C:\Users\90009672\Desktop\baba\" & pictname & ".jpg").Select 'Path to where pictures are stored
With cPic
.LockAspectRatio = msoFalse
.Height = 80#
.Width = 80#
.Left = Cells(pasterow, 1).Left + Cells(pasterow, 1).Width / 2 - .Width / 2
.Top = Cells(pasterow, 1).Top + Cells(pasterow, 1).Height / 2 - .Height / 2
End With
Next x
Set cPic = Nothing
End Sub
Can I ask you help with the following VBA code?
It works fine. However when the formula find an empty cell it stops. I would like it to keep on going despite the empty cells here and there and stop when the are no more cells with text.
Thank you for you help
Sub Picture()
Dim pictname As String
Dim pastehere As Range
Dim pasterow As Long
Dim x As Long
Dim lastrow As Long, cPic
lastrow = Worksheets("sheet1").Range("B1").CurrentRegion.Rows.Count
x = 2
For x = 2 To lastrow
Set pastehere = Cells(x, 1)
pasterow = pastehere.Row
Cells(pasterow, 1).Select 'This is where picture will be inserted
pictname = Cells(x, 2) 'This is the picture name
Set cPic = ActiveSheet.Shapes.AddPicture("C:\Users\90009672\Desktop\baba\" & pictname & ".jpg", False, True, PosizLeft, PositTop, True, True)
' ActiveSheet.Pictures.Insert("C:\Users\90009672\Desktop\baba\" & pictname & ".jpg").Select 'Path to where pictures are stored
With cPic
.LockAspectRatio = msoFalse
.Height = 80#
.Width = 80#
.Left = Cells(pasterow, 1).Left + Cells(pasterow, 1).Width / 2 - .Width / 2
.Top = Cells(pasterow, 1).Top + Cells(pasterow, 1).Height / 2 - .Height / 2
End With
Next x
Set cPic = Nothing
End Sub