+ Reply to Thread
Results 1 to 7 of 7

deleting all shapes with same name except one in a sheet

  1. #1
    Registered User
    Join Date
    09-14-2015
    Location
    india
    MS-Off Ver
    2010
    Posts
    38

    deleting all shapes with same name except one in a sheet

    Hi

    I have a signature in jpg format, which I am copying to two different places in the same sheet by using this code

    Please Login or Register  to view this content.
    Now I want to delete these two signatures only, by keeping one (let's say original) in tact

    I am trying with this but it throws an error

    Please Login or Register  to view this content.
    Please help

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: deleting all shapes with same name except one in a sheet

    You cannot use a Shape object to iterate through a Range object.

    Your method to duplicate the shapes results in duplicate names (I was surprised this was possible). The best practice would be to give them unique names when you create the duplicates.

    Also note that this declaration
    Please Login or Register  to view this content.
    creates oShape1 as a Variant because there is no data type, and oshape2 as a Shape. You must give a data type for every variable.

    The first Sub creates two duplicates. The second Sub deletes the duplicates, leaving the original.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: deleting all shapes with same name except one in a sheet

    Hi there,

    As Jeff correctly points out, it is surprising that Excel allows Shapes with identical names to exist on a single worksheet, but I guess that this is one of Excel's vagaries

    Just to show that there is usually more than one way to skin a cat when using Excel, the following code will delete all but one of the Shapes which have the same name - the Shape allowed to remain is the one which is closest to the top of the worksheet:

    Please Login or Register  to view this content.

    Hope this helps - I also hope that Jeff doesn't mind me jumping in here.

    Regards,

    Greg M

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: deleting all shapes with same name except one in a sheet

    Quote Originally Posted by Greg M View Post
    I also hope that Jeff doesn't mind me jumping in here.
    The more the merrier!

  5. #5
    Registered User
    Join Date
    09-14-2015
    Location
    india
    MS-Off Ver
    2010
    Posts
    38

    Re: deleting all shapes with same name except one in a sheet

    Thanks a lot
    It's working nicely

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,950

    Re: deleting all shapes with same name except one in a sheet

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: deleting all shapes with same name except one in a sheet

    Hi again,

    Many thanks for your feedback - much appreciated!

    You're welcome - glad I was able to help.

    Regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding/Deleting Shapes
    By ShannonC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2021, 04:42 PM
  2. [SOLVED] VBA - Grouping Shapes & Deleting Them
    By CUCE in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-03-2020, 06:39 PM
  3. [SOLVED] Deleting shapes not working
    By peakoverload in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-15-2018, 01:09 PM
  4. [SOLVED] Shapes and Deleting Shapes
    By rob_h in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2017, 10:07 AM
  5. Deleting Shapes
    By Dean81 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2011, 01:25 PM
  6. Deleting Shapes
    By aftamath in forum Excel General
    Replies: 5
    Last Post: 11-04-2005, 08:45 PM
  7. [SOLVED] Deleting Shapes in a worksheet
    By Glen Mettler in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-11-2005, 06:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1