i want to load another picture into image control

Ernest Ansah

New Member
Joined
Oct 12, 2022
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$7" Then
If Sheet14.Range(Target.Address) = "1" Then Sheet14.image1.picture = LoadPicture("C:\Users\Public\Pictures\1.jpg")

If Sheet14.Range(Target.Address) = "2" Then Sheet14.image1.picture = LoadPicture("C:\Users\Public\Pictures\2.jpg")
ElseIf Sheet14.image1.picture = LoadPicture("C:\Users\Public\Pictures\"".jpg") Then Sheet14.image1.picture = LoadPicture("C:\Users\d\AppData\Roaming\BS1 PHOTO\BLANK.jpg")
end if
end sub

please help me correct the error. Thank You
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
A more easy to read version:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("B7")) Is Nothing Then
    If Sheet14.Range(Target.Address) = "1" Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\Public\Pictures\1.jpg")
    End If
    If Sheet14.Range(Target.Address) = "2" Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\Public\Pictures\2.jpg")
    End If
  Else
    If Sheet14.Image1.Picture Is Nothing Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\d\AppData\Roaming\BS1 PHOTO\BLANK.jpg")
    End If
  End If
End Sub
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
A more easy to read version:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("B7")) Is Nothing Then
    If Sheet14.Range(Target.Address) = "1" Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\Public\Pictures\1.jpg")
    End If
    If Sheet14.Range(Target.Address) = "2" Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\Public\Pictures\2.jpg")
    End If
  Else
    If Sheet14.Image1.Picture Is Nothing Then
      Sheet14.Image1.Picture = LoadPicture("C:\Users\d\AppData\Roaming\BS1 PHOTO\BLANK.jpg")
    End If
  End If
End Sub
Thank you but i still have some errors
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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