S
stakar
Hi!
I have a little problem with a part of a code.
At first i use the following code to copy paste a rectangle to a
range.
-------------------------------------------------------------------
Sub Test()
Dim Rng As Range
Dim c As Range
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A3:A" & ws.Range("B65536").End(xlUp).Row)
Application.ScreenUpdating = False
ws.Shapes("Rectangle 51").Copy
For Each c In Rng
c.Select
ws.Paste
Next c
ws.Range("A1").Select
Application.ScreenUpdating = True
End Sub
-------------------------------------------------------------------------------
So far so good
Then i want to delete the all rectangles except the "rectangle 51"
which is in the cell A2
I use the following code
---------------------------------------------------------------------------------
Sub ShapesInRangeDelete()
Dim sh As Shape
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A4:A" & ws.Range("B65536").End(xlUp).Row)
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 when it goes to the line
--If Not Application.Intersect(sh.TopLeftCell, Rng) Is Nothing Then
it gives me an error 1004
Can someone give me an idea??
Thanks in advance
Stathis
I have a little problem with a part of a code.
At first i use the following code to copy paste a rectangle to a
range.
-------------------------------------------------------------------
Sub Test()
Dim Rng As Range
Dim c As Range
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A3:A" & ws.Range("B65536").End(xlUp).Row)
Application.ScreenUpdating = False
ws.Shapes("Rectangle 51").Copy
For Each c In Rng
c.Select
ws.Paste
Next c
ws.Range("A1").Select
Application.ScreenUpdating = True
End Sub
-------------------------------------------------------------------------------
So far so good
Then i want to delete the all rectangles except the "rectangle 51"
which is in the cell A2
I use the following code
---------------------------------------------------------------------------------
Sub ShapesInRangeDelete()
Dim sh As Shape
Dim ws As Worksheet
Set ws = Worksheets("Result")
Set Rng = ws.Range("A4:A" & ws.Range("B65536").End(xlUp).Row)
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 when it goes to the line
--If Not Application.Intersect(sh.TopLeftCell, Rng) Is Nothing Then
it gives me an error 1004
Can someone give me an idea??
Thanks in advance
Stathis