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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
 
Upvote 0
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????
 
Upvote 0

Forum statistics

Threads
1,215,519
Messages
6,125,297
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top