Deleting all pictures / shapes in a range

toboggan

Board Regular
Joined
May 12, 2014
Messages
72
I've been searching and searching to find an answer for this and, while I've found many answers, none of them seem to be working for me. I'm trying to copy several rows and then paste them below. There is a specific area that will sometimes have pictures and/or shapes that I don't want to copy down to the newly created rows. So I'm trying to select the shapes within the newly created area and delete them.

Most of the code I've found so far seem to be some variation of this:

Code:
Dim sh As Shape
    For Each sh In ActiveSheet.Shapes
            If Not Intersect(Range("B454:AA480"), sh.TopLeftCell) Is Nothing And _
               Not Intersect(Range("B454:AA480"), sh.BottomRightCell) Is Nothing Then
                sh.Delete
            End If
        Next sh

However, this code is giving me Run-time error '1004': Application-defined or object-defined error.


Weird thing is. I ran it once and it seemed to work, but if I delete the rows that were created and run the macro again, I continuously get the error above.
 
Right, but it's not within the range. Additionally, it appears as if when the drop down boxes are filled in with data, it works, but when one of the boxes is blank, it gives an error. Further, if it's blank and you get an error once, it will continue to give that error even after filling it in. I'll see if I can fix it by putting data in the box, then run the code that deletes the shapes, and then delete the data in the box.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Maybe:

Code:
    Dim sh As Shape
    For Each sh In ActiveSheet.Shapes
            If sh.Type <> msoFormControl Then
                If Not Intersect(Range("B454:AA480"), sh.TopLeftCell) Is Nothing And _
                   Not Intersect(Range("B454:AA480"), sh.BottomRightCell) Is Nothing Then
                    sh.Delete
                End If
            End If
        Next sh
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,610
Members
449,174
Latest member
ExcelfromGermany

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