+ Reply to Thread
Results 1 to 4 of 4

Remove duplicated cells based on a column value BUT not deleting the repeating headers.

Hybrid View

msls09 Remove duplicated cells based... 09-11-2012, 01:23 AM
nilem Re: Remove duplicated cells... 09-11-2012, 01:45 AM
msls09 Re: Remove duplicated cells... 09-11-2012, 02:19 AM
msls09 Re: Remove duplicated cells... 09-11-2012, 01:56 AM
  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    24

    Remove duplicated cells based on a column value BUT not deleting the repeating headers.

    Hi,

    I have a long spreadsheet with 4 columns which comes like:

    Name Age Address Phone Number
    M. Li 56 FL 1
    J. Jones 43 NJ 2
    K. Smith 52 FL 3
    J. Jones 43 NJ 2

    Name Age Address Phone Number
    M. Li 56 FL 1
    J. Jones 43 NJ 2
    L. Peters 20 ND 4
    A. Kate 25 SD 3

    Name Age Address Phone Number
    K. Car 24 FL 5


    and it goes on like this.

    What I would need is a macro that would look for the phone number (the forth column) and delete all the duplicates but leaves the header so that the end result would look like:

    Name Age Address Phone Number
    M. Li 56 FL 1
    J. Jones 43 NJ 2
    K. Smith 52 FL 3

    Name Age Address Phone Number
    L. Peters 20 ND 4

    Name Age Address Phone Number
    K. Car 24 FL 5

    Basically what I would need is to have it delete all the duplicates except if it contains "Phone Number". I could get it delete the duplicates but am unable to add a condition to prevent it from deleting the headers (which I need so as to keep my information in block for the distribution of work).

    Would be grateful if you could help.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Remove duplicated cells based on a column value BUT not deleting the repeating headers

    try it
    Sub ert()
    Dim x, rDel As Range, i&, s$
    x = Range("D1", Cells(Rows.Count, 4).End(xlUp)).Value: Set rDel = Range("A1")
    On Error Resume Next
    With New Collection
        For i = 1 To UBound(x)
            If Len(x(i, 1)) Then
                If Not x(i, 1) Like "Phone*" Then
                    s = CStr(x(i, 1))
                    If IsEmpty(.Item(s)) Then
                        .Add 1, s
                    Else
                        Set rDel = Union(Cells(i, 4), rDel)
    End If: End If: End If: Next i: End With
    If Not rDel Is Nothing Then Intersect(Columns(4), rDel).EntireRow.Delete
    End Sub

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Remove duplicated cells based on a column value BUT not deleting the repeating headers

    Worked perfectly. Absolute genius! Many many thanks.

  4. #4
    Registered User
    Join Date
    08-21-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Remove duplicated cells based on a column value BUT not deleting the repeating headers

    Worked perfectly. Absolute genius! Many many thanks.

+ 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