Delete Shapes Only Within A Particular Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code below that a member here at Mr Excel provided me to clear any shapes that might remain in my workspace after I clear the cell contents in range ("J3:BM1102")

Code:
rivate Sub Workbook_Open()
    'Stop
    ini1
    
    svcCnt = 0
    svcRid = 0
    mbevents = True
    
    'Stop
    With ws_front
        .Activate
        ActiveWindow.ScrollRow = 1
        ActiveWindow.ScrollColumn = 1
        .Unprotect
        With ws_front.Range("J3:BM1102")
            .Clear
            For Each shp In .Parent.Shapes
                If Not Intersect(shp.TopLeftCell, .Cells) Is Nothing Then shp.Delete
            Next shp
        End With
        mbevents = False
        .Range("A1") = "Enter Date"
        .Range("A2") = Format(0, "00000") 'date serial
        .Range("D2") = Format(0, "000") 'record
        .Range("E2:F2").Locked = True
        .Range("E2") = svcRid
        .Range("G2") = svcCnt
        .Range("A3:A5") = ""
        .Shapes("hidden1").Visible = False
        .Shapes("hidden2").Visible = False
        .Shapes("hidden3").Visible = False
        .Range("M1,O1,M2,O2,U1,U2,W1,W2,AD1, AD1, AD2,AF1, AF2") = 0
        ws_staff.Range("D4:M33").Clear
        mbevents = True
        .Protect
    End With
    
End Sub

I have shapes at H3, H4, and H5 that I want to keep. Does the code above delete them also. I'm guessing it does as I seem to be unable to keep them. If this code is indeed deleting them, how can I change this code to only delete shapes within the Range("J3:BM1102")?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Disregard. This is not happening. What I thought were shapes are actually pictures, so not affected by this code.
But this has introduced a new problem.
 
Upvote 0
Actually, pictures are part of the shapes collection. So any picture located within your specified range will be deleted.
 
Upvote 0
OK, thanks for the clarification Domenic. Whatever I did, I don't seem to be experiencing the initial issue anymore.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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