Hi - I have two sets of employee data from two sources, both in separate worksheets within the same workbook. Both sets of data have same 5 columns, e.g employee number, employee name, line manager, email address and department. I need to compare (based on the unique employee number) of any of the values are different between the two worksheets and highlight the cell if they are.
I have the below code which helps me to compare one column (the emp no) but can anyone help me how I could extend that to compare all the other 4 columns.
Sub CompareLists()
Dim Rng As Range, RngList As Object
Set RngList = CreateObject("Scripting.Dictionary")
Worksheets("Employee1").Activate
'''Make a list of the ColumnA items...
For Each Rng In Worksheets("Employee1").Range("A2", Range("A" & Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
RngList.Add Rng.Value, Nothing
End If
Next
Worksheets("Employee2").Activate
'''Go through Col.A and test for existance of each value in Col.A
'''(Highlight items in Column A that are NOT found in Column A in other sheet)
For Each Rng In Worksheets("Employee2").Range("A2", Range("A" & Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
Rng.Interior.ColorIndex = 3
End If
Next
Set List = Nothing
End Sub
I have the below code which helps me to compare one column (the emp no) but can anyone help me how I could extend that to compare all the other 4 columns.
Sub CompareLists()
Dim Rng As Range, RngList As Object
Set RngList = CreateObject("Scripting.Dictionary")
Worksheets("Employee1").Activate
'''Make a list of the ColumnA items...
For Each Rng In Worksheets("Employee1").Range("A2", Range("A" & Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
RngList.Add Rng.Value, Nothing
End If
Next
Worksheets("Employee2").Activate
'''Go through Col.A and test for existance of each value in Col.A
'''(Highlight items in Column A that are NOT found in Column A in other sheet)
For Each Rng In Worksheets("Employee2").Range("A2", Range("A" & Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
Rng.Interior.ColorIndex = 3
End If
Next
Set List = Nothing
End Sub