Hello -
I have a problem where I need to loop through 2 workbooks, determine if there are the same amount of entries for each Name, and
update one column if need be.
Attached are the two workbooks - the idea is to update what I highlighted in red in the _update file and say that BBB has more entries
in the _update file.
Here is a sample of the code :
Can anyone tell me if I am headed in the right direction?
{/CODE]
I have a problem where I need to loop through 2 workbooks, determine if there are the same amount of entries for each Name, and
update one column if need be.
Attached are the two workbooks - the idea is to update what I highlighted in red in the _update file and say that BBB has more entries
in the _update file.
Here is a sample of the code :
Can anyone tell me if I am headed in the right direction?
Code:
Sub go()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim rng1 As Range
Dim rng2 As Range
Dim nam, group, color, number, typ As Byte
Dim done As String
Dim last1 As Long
Dim last2 As Long
done = "done"
For Each wb1 In Workbooks
If wb1.name Like "file_master*" Then
wb1.Activate
Sheets("Sheet1").Activate
Set rng1 = wb1.Worksheets("Sheet1").Range("A:A")
Else
End If
Next wb1
For Each wb2 In Workbooks
If wb2.name Like "file_update*" Then
wb2.Activate
Sheets("Sheet1").Activate
Set rng2 = wb2.Worksheets("Sheet1").Range("A:A")
Else
End If
Next wb2
last1 = rng1.End(xlDown).Row
last2 = rng2.End(xlDown).Row
For i = 1 To lastrowone
If cel1.Value = cel2.Value Then
nam = True
If cel1.Offset(0, 1) = cel2.Offset(0, 1) Then
group = True
If cel1.Offset(0, 2) = cel2.Offset(0, 2) Then
color = True
If cel1.Offset(0, 3) = cel2.Offset(0, 3) Then
number = True
If cel1.Offset(0, 4) = cel2.Offset(0, 4) Then
typ = True
Else
cel2.Offset(0, 4) = cel1.Offset(0, 4)
cel2.Offset(0, 7) = done
End If
Else
End If
Else
End If
Else
End If
Else
End If
Next i
End Sub
[CODE=vba]
{/CODE]