+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    418

    Macro to delete an entire row if a duplicate entry appears only in a certain column.

    Is there a macro to delete an entire row if a duplicate entry appears only in a certain column.


    1. Look for the column header with the name "File Number"
    2. Anytime the same number under the "File Number" column appears more than once in that column, keep the row that contains first occurrence of that number buy delete the entire row anytime that number is repeated in another row in that same column.

    This is regardless of what is contained in the other columns.


    For example..let's say these cells contained this data...

    B1 - UTE00225
    B2 - UTE00546
    B3 - UTE65513
    B4 - UTE00225
    B5 - UTE00225

    In this case, I would want to keep rows 1, 2, and 3. But, I would want to delete rows 4 & 5 because the number "UTE00225" has already appeared first in B1.

    I'm using Excel 2003.

    P.S. I don't really have code here, so I'm not sure if I should've wrapped it or not. On the flip side, I was also afraid of a forum rule violation if I DID wrap it and shouldn't have. If I should have wrapped any portion of my message, please let me know and I'll be sure to fix it.

    Thanks much.
    Last edited by duugg; 02-25-2009 at 07:00 PM.

  2. #2
    Registered User
    Join Date
    02-17-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Macro to delete an entire row if a duplicate entry appears only in a certain colu

    this will look at the cells in column B row by row, deleting rows with duplicate values, until it gets to a blank cell in column B:

    Code:
    Sub test()
    r = 1
    Do
        Do While Application.WorksheetFunction.CountIf(ActiveSheet.Range("B:B"), Cells(r, 2)) > 1
             ActiveSheet.Range("B:B").Find(Cells(r, 2), Cells(r, 2)).EntireRow.Delete
        Loop
        r = r + 1
    Loop Until Cells(r, 2) = ""
    End Sub

  3. #3
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    418

    Re: Macro to delete an entire row if a duplicate entry appears only in a certain colu

    Dusty,

    That worked perfectly! Thanks!

Thread Information

Users Browsing this Thread

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

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