+ Reply to Thread
Results 1 to 7 of 7

Deleting Rows based on duplicate value

  1. #1
    Registered User
    Join Date
    07-10-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    11

    Deleting Rows based on duplicate value

    Good evening all.

    I have learned how to delete rows based on a specific value. I am now stuck on how to delete rows based on duplicate values. For example, if row x = red and row x+1 = red, then I would like the Macro to leave the row x and delete row x+1.

    In the sample data attached, the duplicate values are geographic countries. As mentioned before, I can delete the data based on a specific value. For example, if I wanted to delete Algeria from the list, my macro is as follows:
    Please Login or Register  to view this content.

    Please how would I adjust this sub routine to do a For next loop where it reads the first country, skips, and then deletes the following rows with duplicate countries. The attached has a before and after if that helps. Many thanks.
    Attached Files Attached Files
    Last edited by alansidman; 08-14-2018 at 03:32 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2403 Win 11 Home 64 Bit
    Posts
    23,810

    Re: Deleting Rows based on duplicate value

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-10-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    11

    Re: Deleting Rows based on duplicate value

    Hi Alansidman,

    Thanks for the notice. I will keep this in mind in future.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2403 Win 11 Home 64 Bit
    Posts
    23,810

    Re: Deleting Rows based on duplicate value

    Here is code I use to delete duplicates in a particular column

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,464

    Re: Deleting Rows based on duplicate value

    Delete 1st row of your attachment then run the code.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-10-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    11

    Re: Deleting Rows based on duplicate value

    Hi Alansidman,

    Thanks for the tip. I will give this code a try and have fun interpreting it.

  7. #7
    Registered User
    Join Date
    07-10-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    11

    Re: Deleting Rows based on duplicate value

    Quote Originally Posted by jindon View Post
    Delete 1st row of your attachment then run the code.
    Please Login or Register  to view this content.
    Hi Jindon, many thanks for the help. I will give this code a try also.

+ 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. Deleting Duplicate Rows with vba
    By Scrapnforfun in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 03-11-2017, 09:57 PM
  2. Code for Eliminating duplicate rows and re arrange without deleting rows
    By pvsvprasad in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-21-2016, 02:42 PM
  3. [SOLVED] Deleting Duplicate Rows???
    By jerickson in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-27-2012, 01:02 PM
  4. [SOLVED] Deleting duplicate rows
    By khenneous in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2012, 09:52 PM
  5. Deleting duplicate rows
    By mljs54 in forum Excel General
    Replies: 4
    Last Post: 11-07-2011, 05:55 AM
  6. deleting duplicate rows based on 2 criteria
    By Zygoid in forum Excel General
    Replies: 1
    Last Post: 04-25-2007, 01:17 PM
  7. Need Help with Deleting Duplicate rows
    By japorms in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2006, 01:25 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