Excel VBA delete picture

williamu

New Member
Joined
Mar 19, 2019
Messages
16
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
I want to delete picture based on cell value
If Target.Value = "Yes" Then delete RedArrow picture should only show GreenArrow picture not both
If Target.Value = "No" Then delete GreenArrow picture
should only show RedArrow picture not both
<strike></strike>

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
Application.ScreenUpdating = False
Range("A9").Select
ActiveSheet.Pictures.Insert ( _
"C:\Users\wurse\OneDrive\Pictures\GreenArrow.png")
Selection.Name = "GreenArrow.png"
Application.ScreenUpdating = True[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Else
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
If Target.Value = "No" Then
Application.ScreenUpdating = False
Range("C9").Select
ActiveSheet.Pictures.Insert ( _
"C:\Users\wurse\OneDrive\Pictures\RedArrow.png")
Selection.Name = "RedArrow.png"
Application.ScreenUpdating = True
Else
End If
End If[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]End Sub[/FONT]
<strike></strike>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi

Instead of loading the picture each time F13 changes it would be much simpler if you would just add the 2 pictures 1 time and then make them visible or not, according to the value in F13

Try this

Add the 2 pictures, name one "RedArrow" and the other "GreenArrow" and use

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
If (Target.Value <> "Yes") And (Target.Value <> "No") Then Exit Sub

Pictures("RedArrow").Visible = (Target.Value = "Yes")
Pictures("GreenArrow").Visible = (Target.Value = "No")
End Sub
 
Last edited:
Upvote 0
Hi

Instead of loading the picture each time F13 changes it would be much simpler if you would just add the 2 pictures 1 time and then make them visible or not, according to the value in F13

Try this

Add the 2 pictures, name one "RedArrow" and the other "GreenArrow" and use

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
If (Target.Value <> "Yes") And (Target.Value <> "No") Then Exit Sub

Pictures("RedArrow").Visible = (Target.Value = "Yes")
Pictures("GreenArrow").Visible = (Target.Value = "No")
End Sub

Thank you pgc01 works great
 
Upvote 0
I want to delete picture based on cell value
If Target.Value = "Yes" Then delete RedArrow picture should only show GreenArrow picture not both
If Target.Value = "No" Then delete GreenArrow picture
should only show RedArrow picture not both
<strike></strike>

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
Application.ScreenUpdating = False
Range("A9").Select
ActiveSheet.Pictures.Insert ( _
"C:\Users\wurse\OneDrive\Pictures\GreenArrow.png")
Selection.Name = "GreenArrow.png"
Application.ScreenUpdating = True


Else
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Address <> "$F$13" Then Exit Sub
If Target.Value = "No" Then
Application.ScreenUpdating = False
Range("C9").Select
ActiveSheet.Pictures.Insert ( _
"C:\Users\wurse\OneDrive\Pictures\RedArrow.png")
Selection.Name = "RedArrow.png"
Application.ScreenUpdating = True
Else
End If
End If

End Sub
<strike></strike>


one more thing when I input the data in cell F13 it works fine but I want to pull data from another worksheet to fill data in cell F13 VBA code does not recognize the change.
 
Upvote 0
one more thing when I input the data in cell F13 it works fine but I want to pull data from another worksheet to fill data in cell F13 VBA code does not recognize the change.

No, this is a change event, it only fires if you write a value in the cell, manually or with code, not with a formula.
If F13 has a formula then use the change event on the cell that you changed.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,428
Members
448,896
Latest member
MadMarty

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