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>
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,778
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:

williamu

New Member
Joined
Mar 19, 2019
Messages
16
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
 

williamu

New Member
Joined
Mar 19, 2019
Messages
16
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.
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,778
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,777
Messages
5,470,714
Members
406,719
Latest member
ensbana

This Week's Hot Topics

Top