Hello everyone.
I need a VBA to compare two sheets and highlights the unique values.
I have this VBA, but it also highlights if a cell changed it´s position, which I don’t need. I only need the VBA to highlight which cells have different values and the unique cells in each sheets.
Thanks for listening.
I need a VBA to compare two sheets and highlights the unique values.
I have this VBA, but it also highlights if a cell changed it´s position, which I don’t need. I only need the VBA to highlight which cells have different values and the unique cells in each sheets.
VBA Code:
Sub Compare_Two_Excel_Sheets()
'Define Fields
Dim iR As Double, iC As Double, oRw As Double
Dim iRow_M As Double, iCol_M As Double
Dim s1 As Worksheet, s2 As Worksheet
Dim s3 As Worksheet
Set s1 = ThisWorkbook.Sheets(1)
Set s2 = ThisWorkbook.Sheets(2)
Set s3 = ThisWorkbook.Sheets(3)
iRow_M = s1.UsedRange.Rows.Count
iCol_M = s1.UsedRange.Columns.Count
For iR = 1 To iRow_M
For iC = 1 To iCol_M
s1.Cells(iR, iC).Interior.Color = xlNone
s2.Cells(iR, iC).Interior.Color = xlNone
If s1.Cells(iR, iC) <> s2.Cells(iR, iC) Then
s1.Cells(iR, iC).Interior.Color = vbYellow
s2.Cells(iR, iC).Interior.Color = vbYellow
oRw = oRw + 1
s3.Cells(oRw, 1) = s1.Cells(iR, iC)
s3.Cells(oRw, 2) = s2.Cells(iR, iC)
End If
Next iC
Next iR
End Sub
Thanks for listening.