+ Reply to Thread
Results 1 to 3 of 3

Thread: Merging two contacts files

  1. #1
    Registered User
    Join Date
    03-14-2011
    Location
    malaysia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Lightbulb Merging two contacts files

    Hi guys. I'm new here and I really need help from all of you.

    I have always been keeping a backup of my phone contacts in the form of excel workbook and I want to merge my files together. I wish to keep the old ones and add in the new ones.

    I can't be doing them one by one as I have over 300 contacts to be sorted out.

    Is there any quick way for me to merge my contacts files together within a few clicks?

    Really appreciate your help guys and girls. Thanks lots in advance.

  2. #2
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,161

    Re: Merging two contacts files

    Cut and paste your second file into the first file so long as the formats (columns) are the same. Next copy this code into your vba editor.

    Put your cursor on the first cell containing the name.
    Run the code and it will eliminate all duplicates. Be sure you have back up copies first in case you have a problem.

    Sub DeleteDuplicateRows()
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' DeleteDuplicateRows
    ' This will delete duplicate records, based on the Active Column. That is,
    ' if the same value is found more than once in the Active Column, all but
    ' the first (lowest row number) will be deleted.
    '
    ' To run the macro, select the entire column you wish to scan for
    ' duplicates, and run this procedure.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim r As Long
    Dim n As Long
    Dim V As Variant
    Dim rng As Range
    
    On Error GoTo EndMacro
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    
    Set rng = Application.Intersect(ActiveSheet.UsedRange, _
                        ActiveSheet.Columns(ActiveCell.Column))
    
    Application.StatusBar = "Processing Row: " & Format(rng.Row, "#,##0")
    
    n = 0
    For r = rng.Rows.Count To 2 Step -1
    If r Mod 500 = 0 Then
        Application.StatusBar = "Processing Row: " & Format(r, "#,##0")
    End If
    
    V = rng.Cells(r, 1).Value
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Note that COUNTIF works oddly with a Variant that is equal to vbNullString.
    ' Rather than pass in the variant, you need to pass in vbNullString explicitly.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If V = vbNullString Then
        If Application.WorksheetFunction.CountIf(rng.Columns(1), vbNullString) > 1 Then
            rng.Rows(r).EntireRow.Delete
            n = n + 1
        End If
    Else
        If Application.WorksheetFunction.CountIf(rng.Columns(1), V) > 1 Then
            rng.Rows(r).EntireRow.Delete
            n = n + 1
        End If
    End If
    Next r
    
    EndMacro:
    
    Application.StatusBar = False
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    MsgBox "Duplicate Rows Deleted: " & CStr(n)
    
    
    End Sub

  3. #3
    Registered User
    Join Date
    03-14-2011
    Location
    malaysia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Merging two contacts files

    Oh wow. Thanks for the tip alansidman. I'll work on that.

+ Reply to Thread

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