Delete shapes in selected range

Anonymous
2024-01-26T08:07:49+00:00

Hi,
Is it possible to have a macro that will delete shapes in selected range.
Thank you,

Cousin Excel

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2024-01-26T08:22:19+00:00

    Dear respected Cousin Excel,

    Good day! Thank you for posting to Microsoft Community. We are happy to help you.

    As per your description, es, it is certainly possible to write a VBA macro for Excel that will delete all shapes within a selected range. Here's an example macro that you can use:

    Sub DeleteShapesInRange()

    **Dim shp As Shape** 
    
    **Dim rng As Range** 
    
    **Dim ws As Worksheet** 
    
    **Set ws = ActiveSheet** 
    
    **Set rng = Selection** 
    
     ****     
    
    **For Each shp In ws.Shapes** 
    
        **If Not Intersect(shp.TopLeftCell, rng) Is Nothing Then** 
    
            **shp.Delete** 
    
        **End If** 
    
    **Next shp** 
    

    End Sub

    This macro will iterate through all the shapes in the active sheet.

    1.Press ALT + F11 to open the Visual Basic for Applications editor.

    1. Click Insert > Module to add a new module.

    3.Copy the above VBA code and paste it into the module window.

    4.Close the VBA editor.

    5.To run the macro, press ALT + F8, select DeleteShapesInRange, and then click Run.

    Appreciate your patience and understanding and thank you for your time and cooperation.

    Sincerely,

    Waqas Muhammad

    3 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-01-30T05:55:57+00:00

    Hi respected Cousin Excel,

    I'm writing a follow up this case, and I haven’t received any information from you, may I know have you checked reply? Feel free to post back if you need further assistance.

    Have a good day and stay safe 😊

    Sincerely,

    Waqas Muhammad

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-02-02T04:39:24+00:00

    Dear Waqas,
    I'm surprised. This is the at least second time happening to me.
    I am very sure that I have marked as answer with 5 stars :))
    Maybe I'm leaving the site too quickly before everything settles, reaches. From today on I will be more careful.
    Your answer was perfect.
    Thank you, best regards,
    Cousin Excel

    1 person found this answer helpful.
    0 comments No comments