Consulting

Results 1 to 3 of 3

Thread: Delete duplicates

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Delete duplicates

    I want to create a macro that would find a word in a column and then every other instance of that code it would delete the whole row.

    Ex:
    If I am looking for test in Column A, it finds it in (1, 1) and then finds it in the next 5 rows. It will leave the one in (1, 1) alone and delete all the rows that have test in it.(only if it is in the same column.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Check "Find Method" in the help file, the code example there should be readily adapted to this task.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    or try this:
    [VBA]Sub RemoveDuplicates()
    Worksheets("Sheet1").Range("A1").Sort _
    key1:=Worksheets("Sheet1").Range("A1")
    Set currentCell = Worksheets("Sheet1").Range("A1")
    Do While Not IsEmpty(currentCell)
    Set nextCell = currentCell.Offset(1, 0)
    If nextCell.Value = currentCell.Value Then
    currentCell.EntireRow.Delete
    End If
    Set currentCell = nextCell
    Loop
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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