ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,689
- Office Version
- 2007
- Platform
- Windows
In my worksheet i have a code where when i type a number in a cell in column A its matched photo of which i have named the same as the entered number is automatically placed into the same row but in column B
So A50 i type 123456 when i leave that cell automatically the photo 123456 is now shown in cell B50
My problem is that this has stopped at row 59 and will not enter the photo anymore.
I thought it was the number entered into the cell but as a test i entered the same number into cell A58 and the photo was shown no problem.
I try the same number in row A59 & no photo at all.
So im thinking maybe the code needs to be changed as maybe i previously set it to stop at 60 etc ???
The only code that i think relates to this above info is supplied below.
Can you confirm if its correct as im lost as to where / why the problem is.
Failing that how would i track down the issue.
Thanks
So A50 i type 123456 when i leave that cell automatically the photo 123456 is now shown in cell B50
My problem is that this has stopped at row 59 and will not enter the photo anymore.
I thought it was the number entered into the cell but as a test i entered the same number into cell A58 and the photo was shown no problem.
I try the same number in row A59 & no photo at all.
So im thinking maybe the code needs to be changed as maybe i previously set it to stop at 60 etc ???
The only code that i think relates to this above info is supplied below.
Can you confirm if its correct as im lost as to where / why the problem is.
Failing that how would i track down the issue.
Thanks
Code:
Private Sub Worksheet_Change(ByVal Target As Range) Dim shp As Shape
Dim picPath As String
Dim vFile
picPath = "C:\Users\Ian\Desktop\SKYPE\LOCK PICK ME\"
If Intersect(Target, [A:A]) Is Nothing Then Exit Sub
If Target.Row Mod 20 = 0 Then Exit Sub
On Error GoTo son
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture And shp.TopLeftCell.Address = Target.Offset(0, 1).Address Then
shp.Delete
End If
Next
If Target.Value <> "" Then
ChDrive picPath
ChDir picPath
picPath = picPath & Target.Value & ".jpg"
If Dir(picPath) = "" Then 'picture not there!
If MsgBox("Photo " & Target.Value & " Doesn't exist" & vbCrLf & "Open The Picture Folder ?", vbCritical + vbYesNo, "No Photo Found") = vbYes Then
' prompt to select the picture file
vFile = Application.GetOpenFilename(filefilter:="JPEG image files (*.jpg), *.jpg", Title:="Select image file")
' exit if they cancelled
If vFile = False Then
Exit Sub
Else
picPath = vFile
End If
Else
Exit Sub
End If
End If
With Target.Offset(0, 1)
Set shp = ActiveSheet.Shapes.AddPicture(Filename:=picPath, _
linktofile:=msoFalse, savewithdocument:=msoTrue, _
Left:=.Left + 5, Top:=.Top + 5, Width:=-1, Height:=-1) ' -1 means use default size
shp.LockAspectRatio = msoFalse
shp.Height = .Height - 10
shp.Width = .Width - 10
End With
End If
son:
End Sub