Question : Delete a Autoshape using vba

I have numerous sheets that have Autoshapes on them. The trouble is they are all named AutoShape 34. I think they were all copies of 1 autoshape and then assigned different macros. They all do have different text written on them.
When I try to delete a button using the code below it will delete another AutoShape with the same name.
The AutoShape I need to be able to delete has the text "Exit" on it.
Is there a way to search for the text on a Autoshape and delete it?
Code Snippet:
1:
2:
ActiveSheet.Shapes("AutoShape 34").Select  
    Selection.Cut

Answer : Delete a Autoshape using vba

What if you add a resume next error statement?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Sub FindShape() 'Find Exit button and delete it
 
    Dim myShape
    Dim currentWB As String
    Dim currentWS As String
    currentWB = ActiveWorkbook.Name
    Workbooks(currentWB).Activate
    Sheets("Sheet3").Select
 
On Error Resume Next
 
For Each myShape In ActiveSheet.Shapes
    myShape.Select
    If Selection.Characters.Text = "exit" Then
        Selection.Delete ' Delete the shape
    End If
Next
 
End Sub
Random Solutions  
 
programming4us programming4us