+ Reply to Thread
Results 1 to 4 of 4

Delete Dupes Macro - Error When No Dupes

  1. #1
    Registered User
    Join Date
    02-13-2008
    Posts
    4

    Delete Dupes Macro - Error When No Dupes

    Hi -

    I have the below macro that I have been using, and it works perfect to flag and remove duplicates. But when there are no duplicates found on the sheet, I get an error at the line below in red.

    I am not sure how I would revise this to account for a scenario when there are no duplicates to remove, and I was hoping that someone might be able to assist me here today.

    Thank You SO much in advance!!


    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-29-2014 at 11:53 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Delete Dupes Macro - Error When No Dupes

    Please Login or Register  to view this content.
    needs to be in an if statement, so if ubound(toDel)>0 youre not finding anything, then trying to delete something.


    not tested.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete Dupes Macro - Error When No Dupes

    When deleting a lot of rows from a sheet, I prefer not to delete them individually in a loop. I record the duplicates into a range, then delete the entire noted range all at once at the end. This is the basic approach I use, tweak as needed:

    Please Login or Register  to view this content.
    This macro leaves the first instance of each item found and will delete any found below that first instance.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete Dupes Macro - Error When No Dupes

    Also, I would be remiss for not pointing to the Data > RemoveDuplicates feature available in all the recent versions of Excel. No VBA needed. It can also be triggered with VBA.

+ 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. Compare 2 worksheets, delete dupes and group by back fill color using macro
    By jousterlj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2011, 01:50 PM
  2. Macro to remove Dupes
    By H-Man3 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-24-2011, 12:03 PM
  3. Use Macro to Sum Dupes then delete - Help please
    By annasproule in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-06-2011, 10:38 PM
  4. Delete dupes except first 2
    By light in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-20-2010, 06:14 PM
  5. delete dupes macro
    By vasto in forum Excel General
    Replies: 0
    Last Post: 09-28-2009, 01:38 PM

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