VBA selecting and deleting grouped shape/charts

kkoz84

Board Regular
Joined
Sep 8, 2015
Messages
82
Hi,

i am using the below code:

What its supposed to do is to delete one grouped shapes (one rectangle, plus some charts and possibly few other elements) in the given range.

Then once it is deleted, macro should copy new grouped shape/charts form another sheet based on the predefined name in "list" variable.

Problem is that once macro loops from shapes in range and that one group of objects is deleted, it attemps to loop through it again when object was deleted and returns error as it cannot find nothing. Error is runtime error 1004. This only occurs when I change value in cell N2 as defined in "list" variable, seems like after changing values in range "n2" (it is drop down menu) macro loops again through range when its empty and returns this error.

Would you know whats the issue?

Thanks,

Code:
Sub x()

Dim s As Shape


list = Workbooks("OriginalXXL.xlsm").Sheets("Sheet1").Range("N2")
Sheets("Sheet1").Select


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


Sheet24.Select


ActiveSheet.Shapes.Range(Array(list)).Select
    Selection.Copy
    
    Sheets("Sheet1").Select
    
    Range("B3").Select
    ActiveSheet.Paste
    Range("P4").Select


End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Ok ihave test it a few times and it looks like that if i will move dropdown menu on another sheet then it works fine, but as soon as i have dropdown menu on teh same sheet where shape is being deleted, it creates error as trying to loop to many times. Does it help?
 
Upvote 0
Looks like error is created when new shape is pasted and then when macro tries to delete it there is error.

If i paste same shape all over again then it is deleted with no issue, but as soon as new shape is pasted then error occurs.

Omg this drives me crazy!
 
Upvote 0
Hey,

Just bumping thread, anyone would have any idea, is it possibly some bug? Or i do something wrong?

Thanks,
 
Upvote 0
Nobody would have solution for this please?;/ Do i need to describe topic better? Please helps anyone
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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