Forum

How do I delete ima...
 
Notifications
Clear all

How do I delete images in a specific range

6 Posts
3 Users
0 Reactions
818 Views
(@milena_s)
Posts: 2
New Member
Topic starter
 
I have a macro that imports data from a selected file. The data includes some images. The problem I am having is if i have data and images already in my document, and I go to import new data, the images do not delete and simply get pasted on top of each other. I wrote code to select the cells and clear them, but it doesn't clear the images.

I think the solution is to put some code at the beginning that can select the images in the cell range and delete them, before the new data is imported.

I came across a solution that Selects all images in the worksheet and deletes them, But I have other images that I need to keep.

Is is possible to tell it to select all images in a specific range of cells?

 
Posted : 05/05/2018 3:13 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Milena

Welcome to the forum.

Just select the required range and then run the macro below.

Sub DeletePictures()
Dim Sh As Shape
For Each Sh In ActiveSheet.Shapes
If Not Application.Intersect(Sh.TopLeftCell, Range(Selection.Address)) Is Nothing Then
Sh.Delete
End If
Next Sh
End Sub

Hope this helps.

Sunny

 
Posted : 05/05/2018 8:15 pm
(@milena_s)
Posts: 2
New Member
Topic starter
 

Thank you! The Code that ended up working is this

 

Sub DeleteImage() Dim pic As Picture ActiveSheet.Unprotect For Each pic In ActiveSheet.Pictures If Not Application.Intersect(pic.TopLeftCell, range("H10:R24")) Is Nothing Then pic.Delete End If Next pic End Sub
 
Posted : 08/05/2018 10:16 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Milena

Glad to know you got it solved.

Sunny

 
Posted : 08/05/2018 8:47 pm
(@ttee22)
Posts: 1
New Member
 

Hi

i Tried the exact code and it does nothing for me. idk if its because of my image format (GIF)

 

Sheets("Print PG").Select
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not Intersect(pic.TopLeftCell, Range("A85:K101")) Is Nothing Then
pic.Delete
End If

 
Posted : 19/01/2019 11:54 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Tolu

Your codes looks incomplete.

Both Milena's and my codes work on GIF as well.

Make sure that the images are inside the range you specified.

Why don't you copy our codes and retry again.

Sunny

 
Posted : 20/01/2019 1:00 pm
Share: