I am trying to create a VBA code for adding JPG image into column A with respect to the Value mentioned in column B. But when ever there is a missing image the whole VBA stops. Is there any way to skip this and move on to the next cell. Thanks in Advance.
Sub Picture() Dim pictname As String Dim pastehere As Range Dim pasterow As Long Dim x As Long Dim lastrow As Long 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 ActiveSheet.Pictures.Insert("\\C:\Users\ajith.nair\Desktop\Range\photos for new range Q1\" & pictname & ".jpg").Select 'Path to where pictures are stored With Selection .Left = Cells(pasterow, 1).Left .Top = Cells(pasterow, 1).Top .ShapeRange.LockAspectRatio = msoFalse .ShapeRange.Height = 55# .ShapeRange.Width = 55# .ShapeRange.Rotation = 0# End With Next End Sub