delete picture problem

lpking2005

Board Regular
Joined
Mar 21, 2011
Messages
140
hi, currently i have some code which copy/pastes an image from a workbook into another workbook when I input a order number into Cell (J21)

The problem is that when I insert a different order number, all it does is paste another image on top of the existing image.

I need it to delete the existing picture first before receiving new image and delete the existing picture when Cell (J21) is empty.

Here is the code i am using:

Private Sub Worksheet_Change(ByVal Target As Range)
'paste image from matrix

If Not Intersect(Target, Range("J21", "K22")) Is Nothing Then

If Range("J21").Value <> "" Then
SKU = Range("M23").Value

Workbooks.Open "T:\Production\PROD MOULDING\2 - LINE MANUAL PROJECT\Mouldings Product_Labour Matrix.xls", 0, 1

With Sheets("403").Shapes("" & SKU & "")
.Height = 301
.Width = 101
.Copy
End With

ThisWorkbook.Activate

Sheets("HOME PAGE").Range("Q27").PasteSpecial

With Application
.DisplayAlerts = False
Windows("Mouldings Product_Labour Matrix.xls").Close
.DisplayAlerts = True
End With

Else
'delete shape
End If

End If

End Sub

any help please?
 
Last edited:
It will only work once you have first copied a picture into the sheet and named it "Some unique string".
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Why are you opening another wb? Why use the ws change event? It's seems fairly straight forward... name the shape consistantly. Before pasting the pic, see if it exists, if it does then delete it. Something like this (untested). HTH. Dave
Code:
Dim Sh As Shape
If Sheets("HOME PAGE").Range("J21").Value <> "" Then
With Sheets("HOME PAGE")
For Each Sh In .Shapes
If Sh.Name = "34002932" Then
Sh.Delete
Exit For
End If
Next Sh
End With
Sheets("HOME PAGE").Range("Q27").PasteSpecial
Selection.Name = "34002932"
End If
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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