Delete Shapes in a Range

ultrawat

New Member
Joined
Nov 7, 2005
Messages
47
Hope someone can help.....

I have a worksheet "Proposal" which has some forms buttons, some forms 'tick boxes' and some rectangles drawn with the Drawing rectangle tool.

I want to use a macro to delete any and all of the above which fall into the Range A5:AE190

I have tried:

Sub ShapesInRangeDelete()

Dim sh As Shape
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A5:AE190")

For Each sh In ws.Shapes
If Not Application.Intersect(sh.TopLeftCell, Rng) Is Nothing Then
sh.Delete
End If
Next sh
End Sub


...but get a an "Application defined or Object defined error" on the "If Not...." line.

Can someone offer some suggestions.......

Thanks in advance :-D
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Your code almost works but you made a couple errors.

First, you say in your opening text that your sheet of interest is named "Proposal" but your macro is coded for a sheet named "Result".

Second, you did not declare the variable Rng.

Third, you should set the ws and Rng variables to Nothing to release them from memory, though that did not contribute to your error.

This amended code works for me if the worksheet of interest really is named "Result":




Sub ShapesInRangeDelete()
Dim Rng As Range
Dim sh As Shape
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A5:AE190")
For Each sh In ws.Shapes
If Not Intersect(sh.TopLeftCell, Rng) Is Nothing Then sh.Delete
Next sh
Set Rng = Nothing
Set ws = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,678
Messages
6,186,402
Members
453,352
Latest member
OrionF

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