Hi All,
Found some code from an old post (http://www.excelforum.com/excel-prog...ml#post3701361) which compares data in sheet1 & sheet2 and highlights differences in both sheets.
Applied below code to my sample file (attached) but picked up some limitations which I was hoping someone could help me with:
- Code seems to stop comparing any further once it reaches a blank cell
- Compares dates and values relatively well but not text columns like people's names, department names, etc.
- There also seems to be some inconsistency in comparing which i can't quite figure out
Any help would be greatly appreciated.
Sub Compare()
Dim w1 As Worksheet, w2 As Worksheet
Dim A1 As Range, A2 As Range
Dim r1 As Long, r2 As Long
Set w1 = Sheets("Sheet1"): Set w2 = Sheets("Sheet2")
r1 = w1.Range("A" & Rows.Count).End(xlUp).Row
r2 = w2.Range("A" & Rows.Count).End(xlUp).Row
Sheet1:
For Each A1 In w1.Range("A2:Q" & r1)
If A1 = "" Then GoTo Sheet2
For Each A2 In w2.Range("A2:Q" & r2)
If A1 = A2 Then GoTo GetNext
Next
A1.Interior.Color = vbYellow
GetNext: Next
Sheet2:
For Each A2 In w2.Range("A2:Q" & r2)
If A2 = "" Then Exit Sub
For Each A1 In w1.Range("A2:Q" & r1)
If A1 = A2 Then GoTo GetAnother
Next
A2.Interior.Color = vbYellow
GetAnother: Next
End Sub
Bookmarks