A little trouble with shapes

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
Im trying to remove most of my shapes from my sheet but a few of them Id like to keep They are in cell S21 and ab21

the range of cells i want to delete are stored in range(a27:BS & last row")

Ive tried like this

Code:
     Set Rng = Range(Cells(26, "C"), Cells(lr, "P"))
     
     For Each sh In ActiveSheet.Shapes
        On Error Resume Next
        If Intersect(Rng, sh.TopLeftCell) Is Nothing Then
        Else
           sh.Delete
       End If
     Next sh

But this codes still deletes shapes in S21 and ab21 , which I like to keep. they are Rounded Rectangles 10 shapes total. No mater what I try they get deleted.

Anyone know how I can keep them ?

frederik
 
Another approach would be to add some text to the "Alternative Text" property of the pics that you do not want to delete.

Then the code would be something like:
Code:
for each sh in ActiveSheet.Shapes

    if sh.AlternativeText <> "Don't delete me" then sh.Delete
    
next

This way, it would not matter where on the sheet the shapes are that you don't want to delete.
 
Last edited:
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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