Sub CompareMe()
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim rng1 As Range, rng2 As Range, rng3 As Range
Dim X1(), X2(), X3()
Dim i As Long, j As Long
Set ws1 = Application.InputBox("Click in any cell in the first sheet", "Select sheet1", , , , , , 8).Parent
Set ws2 = Application.InputBox("Click in any cell in the second sheet", "Select sheet2", , , , , , 8).Parent
If ws1.Name = ws2.Name Then
MsgBox "You picked the same 2 sheets", vbCritical
Exit Sub
End If
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set rng1 = ws1.UsedRange
Set rng2 = ws2.Range(rng1.Address)
On Error Resume Next
Sheets("Output").Delete
On Error GoTo 0
Set ws3 = Worksheets.Add
ws3.Name = "Output"
Set rng3 = ws3.Range(rng1.Address)
X1 = rng1
X2 = rng2
X3 = rng3
For i = 1 To UBound(X1, 1)
For j = 1 To UBound(X1, 2)
If X1(i, j) <> X2(i, j) Then
X3(i, j) = "'" & X1(i, j) & " v " & "'" & X2(i, j)
rng1.Cells(i, j).Interior.ColorIndex = 4
End If
Next j
Next i
rng3 = X3
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
|