if the reference was not found let the image form empty

abdul43

Board Regular
Joined
Aug 19, 2011
Messages
58
HI, All
Here is a code which i have for getting pictures from a folder depending on a cell value (Roll No.)....

Private Sub Worksheet_Calculate()

Static OldVal As Variant
If Range("j7").Value <> OldVal Then
Image1.Picture = LoadPicture("D:\School Record on 13-8-14\General School Record\Students data and admission record\Picture record\" & Range("j7").Value & ".jpg")
OldVal = Range("j7").Value
End If
End Sub

now this code worked good but a single problem occurs while the picture is not present with the roll number given in the cell J7 then it shows the first picture and i need what, that it show nothing if this happens.
thanks
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,040
Office Version
  1. 365
Platform
  1. Windows
Would something like this work
Code:
Private Sub Worksheet_Calculate()
    Static OldVal As Variant
    On Error GoTo errhandler
    If Range("j7").Value <> OldVal Then
        image1.Picture = LoadPicture("D:\School Record on 13-8-14\General School Record\Students data and admission record\Picture record\" & Range("j7").Value & ".jpg")
        OldVal = Range("j7").Value
    End If
errhandler:
    If Err.Number = 53 Then
        image1.Picture = LoadPicture("")
    End If
End Sub
 

abdul43

Board Regular
Joined
Aug 19, 2011
Messages
58
Would something like this work
Code:
Private Sub Worksheet_Calculate()
Static OldVal As Variant
On Error GoTo errhandler
If Range("j7").Value <> OldVal Then
image1.Picture = LoadPicture("D:\School Record on 13-8-14\General School Record\Students data and admission record\Picture record\" & Range("j7").Value & ".jpg")
OldVal = Range("j7").Value
End If
errhandler:
If Err.Number = 53 Then
image1.Picture = LoadPicture("")
End If
End Sub

Hi, Once again ofter a much time sir ......will u like to listen something about the code given by u sir???
i have already posted it to the forum but got no answer and i think this will be the work of ur left hand.......
the only thing i need is that in a single sheet i need this code three times mean i need three different pics followed by three difrenet range (one for each pic), is this possible????
 

Watch MrExcel Video

Forum statistics

Threads
1,109,549
Messages
5,529,471
Members
409,884
Latest member
Msinmath
Top