Deleting all shapes (except 2 rectangles that have macros assigned)

adrian.groves

New Member
Joined
Aug 29, 2012
Messages
18
I have written a macro to draw many on shapes on a sheet, plus another to delete the shapes.

I have then assigned the macros to two button on the worksheet but unfortunately my macro to delete the shapes also deletes the macro buttons.

Does anybody have any suggestions?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi, maybe you can test if the shape has a macro assigned and only delete if it doesn't - something like..
Code:
Sub delete_shapes()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
    If shp.OnAction = "" Then shp.Delete
Next shp
End Sub
 
Last edited:
Upvote 0
Brilliant - thank you.

That worked perfectly.

I had been trying to Select All and then deselect the 2 with macro's so this is great.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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