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

Excel VBA Delete Shape Objects Within a Cell Range

Hey,

I have some shapes that I never want to delete so I am trying to delete shape objects within a specified cell range.  I would like to delete all shapes within cell range (B9, I25).  Is this even possible and if so, how could I do this?

Thanks,
Rob
0
RobStl
Asked:
RobStl
  • 2
1 Solution
 
StephenJRCommented:
This will do it if the top left cell is in the range - would that do?
Sub x()

Dim s As Shape

For Each s In ActiveSheet.Shapes
    If Not Intersect(Range("B9:I25"), s.TopLeftCell) Is Nothing Then
        s.Delete
    End If
Next s

End Sub

Open in new window

1
 
StephenJRCommented:
A bit better perhaps as checks bottom right cell too:
Sub x()

Dim s As Shape

For Each s In ActiveSheet.Shapes
    If Not Intersect(Range("B9:I25"), s.TopLeftCell) Is Nothing And _
       Not Intersect(Range("B9:I25"), s.BottomRightCell) Is Nothing Then
        s.Delete
    End If
Next s

End Sub

Open in new window

0
 
RobStlAuthor Commented:
Thank you for your response.  Works great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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