Hi Folks,
What I am trying to do is coding a macro that compares the rows in sheet1 and sheet2 and highlights the differences. You can see the macro for that below.
My problem is that in case a row or more is added or deleted in the first sheet, all other rows shift up/down which results in a lot of cells being marked in the second sheet.
Since I have an identifier in column A I try to implement an extra line which first looks for the same identifier in sheet 1 and once found, compares the rows of sheet 1 and sheet two, which have the same identifier and then marks potential differences.
Since all my ideas have failed so far, or made the file very slow, I hope you can help me out. Thank you very much!
What I am trying to do is coding a macro that compares the rows in sheet1 and sheet2 and highlights the differences. You can see the macro for that below.
My problem is that in case a row or more is added or deleted in the first sheet, all other rows shift up/down which results in a lot of cells being marked in the second sheet.
Since I have an identifier in column A I try to implement an extra line which first looks for the same identifier in sheet 1 and once found, compares the rows of sheet 1 and sheet two, which have the same identifier and then marks potential differences.
Since all my ideas have failed so far, or made the file very slow, I hope you can help me out. Thank you very much!
Code:
<code>Sub comparing()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rCount As Long, cCount As Long
Set sh1 = Worksheets(ActiveWorkbook.Worksheets.Count() - 1)
Set sh2 = Worksheets(ActiveWorkbook.Worksheets.Count)
rCount = sh1.Cells(Rows.Count, 1).End(xlUp).Row
cCount = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
Dim r As Long, c As Integer For r = 1 To rCount For c = 1 To cCount
If sh1.Cells(r, c) <> sh2.Cells(r, c) Then
sh2.Cells(r, c).Interior.ColorIndex = 6
End If
Next c
Next r
</code>End Sub