Sub CompareSheets()
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Dim r2 As Long
Dim m2 As Long
Dim n2 As Long
Dim r3 As Long
Dim m3 As Long
Dim n3 As Long
Dim c As Long
Dim f As Boolean
Application.ScreenUpdating = False
Set ws2 = Worksheets("Sheet2")
m2 = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row
Set ws3 = Worksheets("Sheet3")
m3 = ws3.Cells(ws3.Rows.Count, 1).End(xlUp).Row
Set ws4 = Worksheets("Sheet4")
' Loop through the rows of Sheet2
For r2 = 1 To m2
n2 = ws2.Cells(r2, ws2.Columns.Count).End(xlToLeft).Column
' Loop through the rows of Sheet3
For r3 = 1 To m3
n3 = ws3.Cells(r3, ws3.Columns.Count).End(xlToLeft).Column
If n3 = n2 Then
f = True
For c = 1 To n2
If ws2.Cells(r2, c).Value <> ws3.Cells(r3, c).Value Then
f = False
Exit For
End If
Next c
If f Then
ws4.Cells(r2, 2).Interior.Color = RGB(0, 128, 0)
End If
End If
Next r3
Next r2
Application.ScreenUpdating = True
End Sub