Forum Statistics
- Forum Members:
- Total Threads:
- Total Posts: 6
There are 1 users currently browsing forums.
|
 |

07-10-2009, 12:15 AM
|
|
Registered User
|
|
Join Date: 15 Apr 2009
Location: Israel
MS Office Version:Excel 2003
Posts: 33
|
|
|
Compare two files with the same ID
Please Register to Remove these Ads
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
Last edited by Shark Man; 07-11-2009 at 12:18 AM.
|

07-10-2009, 02:59 AM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,420
|
|
|
Re: Compare two files with the same ID
- Why are the two cells highlighted?
- 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?
- Can you provide a more varied Master data set showing ALL the hurdles that have to be dealt with.
- Can you provide BEFORE/AFTER examples so it's clear what you really need this macro to do?
- 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.
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc Always put your code between [code] and [/code] tags.
|

07-10-2009, 07:37 AM
|
|
Registered User
|
|
Join Date: 15 Apr 2009
Location: Israel
MS Office Version:Excel 2003
Posts: 33
|
|
|
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
|

07-10-2009, 11:47 AM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,420
|
|
|
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?
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc Always put your code between [code] and [/code] tags.
|

07-10-2009, 01:40 PM
|
|
Registered User
|
|
Join Date: 15 Apr 2009
Location: Israel
MS Office Version:Excel 2003
Posts: 33
|
|
|
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
|

07-10-2009, 03:03 PM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,420
|
|
|
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
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc Always put your code between [code] and [/code] tags.
Last edited by JBeaucaire; 07-10-2009 at 03:06 PM.
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|