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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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????
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,600
Messages
5,838,291
Members
430,537
Latest member
Antonio11

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
Top