+ 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
    MS-Off Ver
    MS Office 2019
    Posts
    15,772

    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.)

  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
    MS-Off Ver
    MS Office 2019
    Posts
    15,772

    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
    Posts
    14,649

    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)

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