+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    04-15-2009
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    69

    Compare two files with the same ID

    Hello Experts
    I have one xls sheet with employee’s information, at column A I have ID number -called Mater.
    I have second xls sheet with update employee’s information, at column A i have the same ID number - called update file.

    I need help with VBA code that update the Master file according to the update file (The ID at column A is the key between the files)and mark with color the update.

    The file contain more the 20,000 records and with 10 columns

    See example

    Thanks Alot
    Shark
    Attached Files Attached Files
    Last edited by Shark Man; 07-11-2009 at 12:18 AM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,080

    Re: Compare two files with the same ID

    1. Why are the two cells highlighted?
    2. I see no discernable difference between the Master File and Update file. Have you oversimplified the example data to the point we can't see your need?
    3. Can you provide a more varied Master data set showing ALL the hurdles that have to be dealt with.
    4. Can you provide BEFORE/AFTER examples so it's clear what you really need this macro to do?
    5. Will the update file really have ALL the same # of rows and IDs as the master file? If so, couldn't you just use the update file to replace the master file as is? If not, show a better example of how your update file might actually look.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-15-2009
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Compare two files with the same ID

    Hello Thanks for your help

    I need the update the file because there is same column that will not going to change.

    I attached new xls file with the process, I hope it will be more helpful

    Thanks

    Shark
    Attached Files Attached Files

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,080

    Re: Compare two files with the same ID

    I ask a series of numbered questions and you don't address them all, so I'm left to figure it out on my own.

    1. Why are the two cells highlighted?
    So anytime something from the update files changes something in the Master File, you want the change highlighted in the master file?

    5. Will the update file really have ALL the same # of rows and IDs as the master file? If so, couldn't you just use the update file to replace the master file as is?

    6. You call these "Sheets"...but are they actually separate workbooks? If so, what is the actual name of the master workbook and the name of the update file?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    04-15-2009
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Compare two files with the same ID

    Hello

    Thanks for your time

    1. you are right
    5. Yes the update file contain the same ID and numbers of #.
    I cant use the update file as the new Master becuase there is few columns that will not be update and located only at the Master.
    6.these are seperate workbooks with the name "Master" and "Update"

    Thanks

    Shark

  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,080

    Re: Compare two files with the same ID

    Run this macro from inside the Master file. It will open the UPDATE file from your default directory, update the values and close the update file. If you don't want the update file closed, take out that line of code near the bottom.
    Code:
    Option Explicit
    Sub UpdateMasterFile()
    'JBeaucaire  (7/10/2009)
    Dim LR As Long, Rw As Long, i As Long
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    Workbooks.Open ("Update.xls")
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 2 To LR
            Rw = 0
            On Error Resume Next
            Rw = WorksheetFunction.Match(Range("A" & i), Workbooks("Master.xls").Sheets("Sheet1").Range("A:A"), 0)
            
            If Rw > 0 Then
                With Workbooks("Master.xls").Sheets("Sheet1").Cells(Rw, "B")
                    If Not .Value = Cells(i, "B") Then
                        .Value = Cells(i, "B")
                        .Interior.ColorIndex = 6
                    End If
                End With
                With Workbooks("Master.xls").Sheets("Sheet1").Cells(Rw, "C")
                    If Not .Value = Cells(i, "C") Then
                        .Value = Cells(i, "C")
                        .Interior.ColorIndex = 6
                    End If
                End With
                With Workbooks("Master.xls").Sheets("Sheet1").Cells(Rw, "D")
                    If Not .Value = Cells(i, "D") Then
                        .Value = Cells(i, "D")
                        .Interior.ColorIndex = 6
                    End If
                End With
            
            End If
        Next i
    
    Workbooks("Update.xls").Close False
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub
    Last edited by JBeaucaire; 07-10-2009 at 03:06 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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