• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Excel replace? or VBA? - How to delete randomly placed graphic objects

I received this worksheet and it has randomly placed tiny graphic elements.  How can I get rid of this using find/replace and/or VBA (see graphic)
err
0
brothertruffle880
Asked:
brothertruffle880
  • 2
2 Solutions
 
Shanan212Commented:
Try this

Sub Deleteall()

ActiveWorksheet.Shapes.SelectAll 
Selection.Delete 

End sub

Open in new window

0
 
redmondbCommented:
Hi, brothertruffle880.

This is a problem I've dealt with here a number of times. The code below will delete all Shapes on the active sheet (there's a warning at the start).

Edit: Just seen your post, Shanan212. Yours is a vastly better solution - as long as there aren't tens of thousands of objects when an attempt to delete them all tends to crash Excel.

Regards,
Brian.
Sub Delete_All_Shapes()
Dim xResponse As Long
Dim xShape    As Shape

If ActiveSheet.Shapes.count = 0 Then
    MsgBox ("No Shapes in the current sheet. Run cancelled.")
    Exit Sub
End If

xResponse = MsgBox("About to delete all of the current sheet's Shapes. [" & ActiveSheet.Shapes.count & "]" & Chr(10) _
                                & "('OK' to continue, 'Cancel' to quit.)", vbOKCancel, "Delete All Shapes")
If xResponse = 2 Then Exit Sub

For Each xShape In ActiveSheet.Shapes

    xShape.Delete
    
Next

End Sub

Open in new window

0
 
redmondbCommented:
Thanks, brothertruffle880.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now