?
Solved

Excel VBA Delete Shape Objects Within a Cell Range

Posted on 2011-10-13
3
Medium Priority
?
10,616 Views
Last Modified: 2012-05-12
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
Comment
Question by:RobStl
  • 2
3 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 36963454
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
 
LVL 24

Accepted Solution

by:
StephenJR earned 2000 total points
ID: 36963528
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
 

Author Comment

by:RobStl
ID: 36963611
Thank you for your response.  Works great!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question