Macro to delete autoshapes depending on their colour

simonansell

New Member
Joined
Jun 23, 2010
Messages
6
Hi,

I have a worksheet with lots of auto shapes and wish to be able to delete specific ones depending on their colour and leave the remaining shapes untouched.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
welcome to the board

Rich (BB code):
Sub DeleteThoseShapes()
For Each MyShp In Sheet1.Shapes
 If MyShp.Fill.ForeColor.SchemeColor = 16 Then MyShp.Delete
Next
End Sub

Change Sheet1 and color index to suit yoru needs
 
Upvote 0
Thanks for the code.

When i run this I get a Runtime error 70 and Permission Denied message??

Any ideas

Thanks
 
Upvote 0
The following code works to delete all auto shapes, but I only want to delete certain ones based on their colour.


Sub DeleteAllShapes()

Sheet16.Activate

Dim GetShape As Shape

For Each GetShape In ActiveSheet.Shapes
GetShape.Delete
Next

End Sub
 
Upvote 0
i am on a standalone pc without any servers.

The code below works and deletes all the auto shapes, with getting a runtime error70. How do i change this code to only delete by colour

Sub DeleteAllShapes()

Sheet16.Activate

Dim GetShape As Shape

For Each GetShape In ActiveSheet.Shapes
GetShape.Delete
Next

End Sub
 
Upvote 0
replace GetShape.Delete with this:

If GetShape.Fill.ForeColor.SchemeColor = ColorCode Then GetShape.Delete

i just tried your code here and works fine
 
Upvote 0
When i replace the line you have given, I now get the Runtime error 70 again.

If I change back to my original code it works again (All autoshapes get deleted)

Is there an alternative way to delete specific autoshapes based on a certain criteria?
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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