I have a VBA code, which inserts image in Excel sheet in the right cell wherever I type image name. But I want it to work only in A:B Ranges: Type Name in cells of column A and it will insert image in the next cell - column B. Here is my code which I want to modify:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Dim myPath As String
myPath = "P:\"
Application.ScreenUpdating = False
For Each c In Target.Cells
If Not Dir(myPath & "*" & c.Text & "*") = "" Then
InsertPicture myPath & Dir(myPath & "*" & c.Text & "*"), c.offset(0, 1)
End If
Next c
Application.ScreenUpdating = True
End Sub
'
Sub InsertPicture(thePath As String, theRange As Range)
With ThisWorkbook.ActiveSheet.Pictures.Insert(thePath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = theRange.Width
.Height = theRange.Height
End With
.Left = theRange.Left
.Top = theRange.Top
.Placement = 1
.PrintObject = True
End With
End Sub
Thank you in advance!