Delete shape but not all

haseft

Active Member
Joined
Jun 10, 2014
Messages
321
Hi!

I want to delte alla shapes but not with the name "rapport".
The shape "rapport" is msoShapeRectangle witch i create in Worksheet.
Other shapes creats in vba'
Please help!

Sub DeleteShapes()
Dim w As Worksheet
Dim s As Shape
Set w = ActiveSheet

For Each s In w.Shapes
If s = "rapport" Then ' want to keep it
'do nothing
Else
s.Delete
End If
Next s
End Sub
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi (Salut ? :) ).

Be careful it's case sensitive :

Code:
Sub test()

    For Each sh In ActiveSheet.Shapes
        If sh.Name <> "rapport" Then
            sh.Delete
        End If
    Next sh

End Sub
 
Last edited:
Upvote 0
Solution
To avoid case-sensitivity:

Code:
If LCase$(sh.Name) <> "rapport" Then
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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