Hi
I need to compare two worksheets based on a unique identifier (column A). Based on the unique identifier, I need a method to easily compare each column between Sheet1 and Sheet2, and any differences reported into a seperate worksheet (Sheet3).
The best I have been able to do is create a simple macro which would compare Sheet1 and Sheet2 but this only HIGHLIGHTS the differences between the two sheets e.g.
Sheet1:
Sheet2:
This kind of helps but ideally I would like to be able to report the differences into a Sheet 3 as follows:
A few caveats:
- The IDs may not be in the same row position between the two sheets
- There may be some IDs in either sheet which don't exist in the other and I need to identify these too.
Below is the macro I currently have:
I've tried searching and can't find anything like this that already exists, if anyone knows of an existing macro which would output in the way I would like, I would appreciate it.
I need to compare two worksheets based on a unique identifier (column A). Based on the unique identifier, I need a method to easily compare each column between Sheet1 and Sheet2, and any differences reported into a seperate worksheet (Sheet3).
The best I have been able to do is create a simple macro which would compare Sheet1 and Sheet2 but this only HIGHLIGHTS the differences between the two sheets e.g.
Sheet1:
Sheet2:
This kind of helps but ideally I would like to be able to report the differences into a Sheet 3 as follows:
A few caveats:
- The IDs may not be in the same row position between the two sheets
- There may be some IDs in either sheet which don't exist in the other and I need to identify these too.
Below is the macro I currently have:
VBA Code:
Option Explicit
Sub DetectChanges()
Dim ws1 As Worksheet, ws2 As Worksheet '<-- explicitly declare each variable type
Dim ws1Data As Range, f As Range, cell As Range
Dim icol As Long
Set ws1Data = Worksheets("Sheet1").Columns(1).SpecialCells(xlCellTypeConstants) '<-- set a range with Sheet1 cells containing data
With Worksheets("Sheet2") '<--| reference Sheet2
For Each cell In Intersect(.UsedRange, .Columns(1)).SpecialCells(xlCellTypeConstants) '<-_| loop through its column "A" non blank cells
Set f = ws1Data.Find(what:=cell.Value, LookIn:=xlValues, LookAt:=xlWhole) '<--| search for current cell value in Sheet1 data
If f Is Nothing Then '<--| if not found then...
Intersect(cell.EntireRow, .UsedRange).Interior.ColorIndex = 3 '<--| highlight current cell entire row
Else
For icol = 1 To .Range(cell, .Cells(cell.Row, .Columns.Count).End(xlToLeft)).Columns.Count - 1 '<--| loop through Sheet2 current cell row
If f.Offset(, icol) <> cell.Offset(, icol) Then '<--| if it doesn't match corresponding cell in Sheet1
cell.Offset(, icol).Interior.ColorIndex = 3 '<--| highlight Sheet2 not-matching cell
f.Offset(, icol).Interior.ColorIndex = 3 '<--| highlight Sheet1 not-matching cell
End If
Next icol
End If
Next cell
End With
End Sub
I've tried searching and can't find anything like this that already exists, if anyone knows of an existing macro which would output in the way I would like, I would appreciate it.