PC Review


Reply
Thread Tools Rate Thread

Delete shapes in a range

 
 
Pam
Guest
Posts: n/a
 
      17th Jul 2008
I'm trying to delete shapes in a range. I have found this code from another
post, but it won't accept "TopLeftCell" (It says method or data member not
found) so I put in the range I wanted it to look in, but it deletes all the
shaps. Can you help me?

Dim sh as Worksheet, sh1 as Worksheet
Dim v as Variant, v1 as Variant
Dim rng as Range, rng1 as Range
Dim shp as Shape, i as Long, j as Long
set sh = Worksheets("Sheet1")
set rng = sh.Range("A11, B22, C33")
for each shp in sh.Shapes
set rng1 = sh.range(sh.TopLeftCell, sh.BottomRightCell)
if not intersect(rng,rng1) is nothing then
shp.Delete
end if
Next

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      18th Jul 2008
TopLeftCell is a property of the shape, not the sheet

Dim sh As Worksheet, sh1 As Worksheet
Dim v As Variant, v1 As Variant
Dim rng As Range, rng1 As Range
Dim shp As Shape, i As Long, j As Long
Set sh = Worksheets("Sheet1")
Set rng = sh.Range("A11, B22, C33")
For Each shp In sh.Shapes

Set rng1 = sh.Range(shp.TopLeftCell, shp.BottomRightCell)
If Not Intersect(rng, rng1) Is Nothing Then

shp.Delete
End If
Next


--
__________________________________
HTH

Bob

"Pam" <(E-Mail Removed)> wrote in message
news:957EEB7D-B62D-4C14-9B9A-(E-Mail Removed)...
> I'm trying to delete shapes in a range. I have found this code from
> another
> post, but it won't accept "TopLeftCell" (It says method or data member not
> found) so I put in the range I wanted it to look in, but it deletes all
> the
> shaps. Can you help me?
>
> Dim sh as Worksheet, sh1 as Worksheet
> Dim v as Variant, v1 as Variant
> Dim rng as Range, rng1 as Range
> Dim shp as Shape, i as Long, j as Long
> set sh = Worksheets("Sheet1")
> set rng = sh.Range("A11, B22, C33")
> for each shp in sh.Shapes
> set rng1 = sh.range(sh.TopLeftCell, sh.BottomRightCell)
> if not intersect(rng,rng1) is nothing then
> shp.Delete
> end if
> Next
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      18th Jul 2008
Both the .topleftcell and .bottomrightcell belong to the shp, not the sh
variable.

set rng1 = sh.range(shp.TopLeftCell, shp.BottomRightCell)

And I would have expected this line:

Set rng = sh.Range("A11, B22, C33")
to look more like:
Set rng = sh.Range("A11:C33")
If you wanted to check all of the cells in A11 to C33????

Pam wrote:
>
> I'm trying to delete shapes in a range. I have found this code from another
> post, but it won't accept "TopLeftCell" (It says method or data member not
> found) so I put in the range I wanted it to look in, but it deletes all the
> shaps. Can you help me?
>
> Dim sh as Worksheet, sh1 as Worksheet
> Dim v as Variant, v1 as Variant
> Dim rng as Range, rng1 as Range
> Dim shp as Shape, i as Long, j as Long
> set sh = Worksheets("Sheet1")
> set rng = sh.Range("A11, B22, C33")
> for each shp in sh.Shapes
> set rng1 = sh.range(sh.TopLeftCell, sh.BottomRightCell)
> if not intersect(rng,rng1) is nothing then
> shp.Delete
> end if
> Next


--

Dave Peterson
 
Reply With Quote
 
Pam
Guest
Posts: n/a
 
      18th Jul 2008
Thank you both very much. I got it to work.

Pam

"Dave Peterson" wrote:

> Both the .topleftcell and .bottomrightcell belong to the shp, not the sh
> variable.
>
> set rng1 = sh.range(shp.TopLeftCell, shp.BottomRightCell)
>
> And I would have expected this line:
>
> Set rng = sh.Range("A11, B22, C33")
> to look more like:
> Set rng = sh.Range("A11:C33")
> If you wanted to check all of the cells in A11 to C33????
>
> Pam wrote:
> >
> > I'm trying to delete shapes in a range. I have found this code from another
> > post, but it won't accept "TopLeftCell" (It says method or data member not
> > found) so I put in the range I wanted it to look in, but it deletes all the
> > shaps. Can you help me?
> >
> > Dim sh as Worksheet, sh1 as Worksheet
> > Dim v as Variant, v1 as Variant
> > Dim rng as Range, rng1 as Range
> > Dim shp as Shape, i as Long, j as Long
> > set sh = Worksheets("Sheet1")
> > set rng = sh.Range("A11, B22, C33")
> > for each shp in sh.Shapes
> > set rng1 = sh.range(sh.TopLeftCell, sh.BottomRightCell)
> > if not intersect(rng,rng1) is nothing then
> > shp.Delete
> > end if
> > Next

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CopyPicture on a Shapes range Kevin Beckham Microsoft Excel Programming 6 6th Aug 2008 01:43 PM
Re: Delete all Shapes from selected Range Chip Pearson Microsoft Excel Programming 0 15th Dec 2006 06:09 PM
how to select ALL named shapes in range Corey Microsoft Excel Programming 1 25th Aug 2006 01:14 AM
Shapes Range Array Bubb Microsoft Excel Misc 1 10th Apr 2006 11:51 PM
Problem Deleting A Range of shapes stakar Microsoft Excel Misc 4 2nd Sep 2004 03:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 PM.