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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,215,708
Messages
6,126,363
Members
449,311
Latest member
accessbob

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