I have a file where there are multiple rows.
Column A has a value and in another column, the corresponding image will appear. If the value is deleted, the corresponding image will disappear. If the value changes, the image will change based on the corresponding value.
My problem is that sometimes it deletes, and sometimes it doesn't. When I tried this on different computers, it worked perfectly but when on another computer, none of the images self delete when the value is deleted.
Can someone help me refine the VBA code I am using?
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pic As Picture
If Intersect(Target, [A:A]) Is Nothing Then Exit Sub
On Error GoTo son
For Each pic In ActiveSheet.Pictures
If Not Application.Intersect(pic.TopLeftCell, Range(Target.Offset(0, 3).Address)) Is Nothing Then
pic.Delete
End If
Next pic
Dim fPath As String
fPath = "G:\My Drive\Images"
'If Target.Value <> "" And Dir(fPath & Target.Value & ".jpg").select
ActiveSheet.Pictures.Insert(fPath & "\" & Target.Value & ".jpg").Select
Selection.Top = Target.Offset(0, 2).Top
Selection.Left = Target.Offset(0, 4).Left
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = Target.Offset(0, 2).Height
Selection.ShapeRange.Width = Target.Offset(0, 4).Width
Target.Offset(0, 1).Select
son:
End Sub
Bookmarks