I am doing my first steps in excel 2007 vba. What I am trying to do is to code a macro that compares my last and my second last excel sheet and highlights the differences in the last one. As you can see below I coded the following and Excel does not display any errors when I use the debug mode, yet it does not mark any cells where a change has been made, which it is suppose to do. Would anyone mind having a look and correct my potential mistakes in the code below. Thank you very much. |
<tbody>
</tbody>
Code:
<code>Sub compare2sheets()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rCount As Long, cCount As Long
Set sh1 = Worksheets(Sheets.Count - 1)
Set sh2 = Worksheets(Sheets.Count)
rCount = sh1.Cells(Rows.Count, 1).End(xlUp).Row
cCount = sh1.Cells(Rows.Count, 1).End(xlUp).Row
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 = 3
End If
Next c
Next r</code>
End Sub
Last edited: