dimples_21188
New Member
- Joined
- Aug 21, 2017
- Messages
- 12
Hello everyone
I would truly appreciate some help. The formula below works beautifully until two different reasons:
1. The cell is blank or,
2. There isn't an picture in the file that matches the name in the cell
Could someone help me find a way to ignore these errors and allow the code to continue.
THANK YOU
Sub Worksheet_change(ByVal Target As Range)
Dim animal_pic As Picture
Dim pic_location As String
Dim animal_name As String
ActiveSheet.Pictures.Delete
For i = 7 To 50
animal_name = Worksheets("Strains").Cells(i, 3).Value
pic_location = "C:\Users\dimpl\Desktop\Strain Tiles\" & Worksheets("Strains").Cells(i, 3).Value & ".png"
With Worksheets("Strains").Cells(i, 1)
Set animal_pic = ActiveSheet.Pictures.Insert(pic_location)
animal_pic.Top = .Top
animal_pic.Left = .Left
animal_pic.ShapeRange.LockAspectRatio = msoFalse
animal_pic.Placement = xlMoveAndSize
animal_pic.ShapeRange.Width = 75
animal_pic.ShapeRange.Height = 75
End With
Next i
End Sub
I would truly appreciate some help. The formula below works beautifully until two different reasons:
1. The cell is blank or,
2. There isn't an picture in the file that matches the name in the cell
Could someone help me find a way to ignore these errors and allow the code to continue.
THANK YOU
Sub Worksheet_change(ByVal Target As Range)
Dim animal_pic As Picture
Dim pic_location As String
Dim animal_name As String
ActiveSheet.Pictures.Delete
For i = 7 To 50
animal_name = Worksheets("Strains").Cells(i, 3).Value
pic_location = "C:\Users\dimpl\Desktop\Strain Tiles\" & Worksheets("Strains").Cells(i, 3).Value & ".png"
With Worksheets("Strains").Cells(i, 1)
Set animal_pic = ActiveSheet.Pictures.Insert(pic_location)
animal_pic.Top = .Top
animal_pic.Left = .Left
animal_pic.ShapeRange.LockAspectRatio = msoFalse
animal_pic.Placement = xlMoveAndSize
animal_pic.ShapeRange.Width = 75
animal_pic.ShapeRange.Height = 75
End With
Next i
End Sub