Consulting

Results 1 to 3 of 3

Thread: Solved: Delete Rows-However keep the first found Row

  1. #1
    VBAX Regular
    Joined
    Jul 2007
    Posts
    18
    Location

    Solved: Delete Rows-However keep the first found Row

    In the attached excel sheet i need to find rows with similar data in coulmn B.
    Then i want to delete all the rows with similar data, except for the first found rows.

    That means only rows 2, 3, 4 & 11 should be the end result.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "B" '<=== change to suit
    Dim i As Long
    Dim mpLastRow As Long
    Dim mpSelected As Range


    With ActiveSheet

    mpLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 2 To mpLastRow
    If Application.CountIf(.Cells(1, TEST_COLUMN).Resize(i), .Cells(i, TEST_COLUMN).Value) > 1 Then
    If mpSelected Is Nothing Then
    Set mpSelected = .Rows(i)
    Else
    Set mpSelected = Union(.Rows(i), mpSelected)
    End If
    End If
    Next i

    If Not mpSelected Is Nothing Then mpSelected.Delete
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2007
    Posts
    18
    Location
    thanks XLD....works perfect.
    is there a book you can recommend to learn codes for excel?

Posting Permissions

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