I have a master file & i get daily updates in a separate file. I need to compare the two files, update the master with changes received, add new rows & highlight missing ones.
to compare the two files I use the following code to iterate the cells, with a unique id called ResourceRequestID(usually in the first two columns). These files have approximately 92 columns & upward of 500 rows (less than 10000 rows). How do i compare two rows & update the master with just the differences? Also, any suggestions to speed up (currently this takes about 5-8 mins) would be greatly appreciated.
'Find demands in master against the demand sheet
Sub FindDemandsInDemandSheet()
Application.ScreenUpdating = False
demandcount = 0
Workbooks(Master).Sheets("Demands").Activate
'Go to A1
Range("A1").Select
'find resource request id
If ActiveCell.Value <> rRIDConst Then
'TODO: Identify the column which has RRID.
End If
'count total number of rows
Range("A1").End(xlDown).Offset(1, 0).Select
demandcount = ActiveCell.Row - 2 'reducing 2 because the XL has a header & we are in the first blank cell in RRID column
Range("A1").End(xlToRight).Offset(0, 1).Select
colCount = ActiveCell.Column - 1
Workbooks(demandSheet).Sheets("Demands").Activate
Range("A1").End(xlDown).Offset(1, 0).Select
destDemandCount = ActiveCell.Row
Workbooks(Master).Sheets("Demands").Activate
'iterate each RRid in master against pdac sheet
For ctr = 2 To demandcount
Range("A" + Trim(Str(ctr))).Select
demandId = ActiveCell.Value
Workbooks(demandSheet).Sheets("Demands").Activate
'if found, get row in destination
yy = "A2:A" + Trim(Str(destDemandCount))
Set x = ActiveSheet.Range("A2:A" + Trim(Str(destDemandCount))).Find(demandId, , -4163)
If Not x Is Nothing Then
destrow = x.Row
'Iterate columns in master
For colCtr = 1 To colCount
Workbooks(demandSheet).Sheets("Demands").Activate
Range("A" + Trim(Str(destrow))).Offset(0, colCtr).Select
destValue = ActiveCell.Value
Workbooks(Master).Sheets("Demands").Activate
Range("A" + Trim(Str(ctr))).Offset(0, colCtr).Select
sourceValue = ActiveCell.Value
'compare each cell &
'if different, copy from demand sheet, highlight cell
If sourceValue <> destValue Then
ActiveCell.Value = destValue
ActiveCell.Interior.Color = vbYellow
End If
Next colCtr
Else
'Demand not found in the latest demand sheet. highlight cell in Red
Workbooks(Master).Sheets("Demands").Activate
Range("A1").Select
With Range("A" + Trim(Str(ctr)))
.Select
.Interior.Color = vbRed
End With
End If
Next ctr
Application.ScreenUpdating = True
MsgBox "Demand Master validated against latest demand reports"
End Sub