ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete drwaings in a centain selection (https://www.excelbanter.com/excel-programming/400065-delete-drwaings-centain-selection.html)

bartman1980

delete drwaings in a centain selection
 
I try to delete all the drawings in a certain selection.

sub deletedrawings()
Range("A60:H60").Select
Range("H60").Activate
Range(Selection, Selection.End(xlDown)).Select
activecells.DrawingObjects(1).Delete
Selection.ClearContents
end sub

But I get an error with the line
activecells.DrawingObjects(1).Delete


Bernie Deitrick

delete drwaings in a centain selection
 
Bartman,

Try something like the sub below.

HTH,
Bernie
MS Excel MVP


Sub DeleteShapes()
Dim myRange As Range
Dim myTop As Double
Dim myLeft As Double
Dim myRight As Double
Dim myBottom As Double
Dim mySh As Shape

Set myRange = Range(Range("A60"), Range("H60").End(xlDown))
myTop = myRange(1).Top
myLeft = myRange(1).Left
myRight = myRange(myRange.Count).Left + myRange(myRange.Count).Width
myBottom = myRange(myRange.Count).Top + myRange(myRange.Count).Height

For Each mySh In ActiveSheet.Shapes
If mySh.Top myTop And mySh.Top < myBottom Then
If mySh.Left myLeft And mySh.Left < myRight Then
mySh.Delete
End If
End If
Next mySh

End Sub



"bartman1980" wrote in message
oups.com...
I try to delete all the drawings in a certain selection.

sub deletedrawings()
Range("A60:H60").Select
Range("H60").Activate
Range(Selection, Selection.End(xlDown)).Select
activecells.DrawingObjects(1).Delete
Selection.ClearContents
end sub

But I get an error with the line
activecells.DrawingObjects(1).Delete





All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com