View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Loop to delete shapes

Thanks Ron..

Daniel, if you are worried about the number of iterations you can get the
..count property to get the number; as in below example

On Error Resume Next
Dim i as Integer
For i = 1 To ActiveSheet.Shapes.Count
ActiveSheet.Shapes(i).Delete
Next i


Just to add on
--
If this post helps click Yes
---------------
Jacob Skaria


"Ron de Bruin" wrote:

Hi Jacob

Your code will not select all shapes types
Maybe no problem for the OP but use this if you want to delete them all (also working OK in 2007)

Sub Shapes1()
'Delete all Objects except Comments
On Error Resume Next
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete
On Error GoTo 0
End Sub

Use this to delete comments

Sub Comments()
'This will delete all comments
ActiveSheet.Cells.ClearComments
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Jacob Skaria" wrote in message ...
Try

Activesheet.shapes.selectall
Selection.delete

If this post helps click Yes
---------------
Jacob Skaria


"Daniel Bonallack" wrote:

I copy data from a webpage to Excel, then clear the shapes and icons off
using this loop. I know, it's so lame and inefficient, especially as there
are usually only 30 or so shapes to delete.

On Error Resume Next
For i = 1 To 2000
ActiveSheet.Shapes("Picture " & i).Select
Selection.Delete
Next i

What I would like is a loop that deletes each image without the redundant
work that the above loop goes through.

Can you help?