sujittalukde
04-21-2008, 01:01 AM
I am using the following code to compare two sheets - Original with revised sheets and want to highlight the rows not matching.
Sub test()
Sheets("Original").Select
olrow = ActiveSheet.UsedRange.Rows.Count
Range("a1").Select
Sheets("revised").Select
rlrow = ActiveSheet.UsedRange.Rows.Count
Range("a1").Select
If olrow > rlrow Then
lastrow = olrow
Else
lastrow = rlow
End If
Sheets("Original").Select
Range("a1").Select
For i = 1 To lrow
Sheets("Original").Select
Range("a" & i).Select
Odt = ActiveCell.Offset(i, 0).Value
Oldgr = ActiveCell.Offset(i, 1).Value
Otot = ActiveCell.Offset(i, 8).Value
Sheets("revised").Select
Range("a" & i).Select
Rdt = ActiveCell.Offset(i, 0).Value
Rldgr = ActiveCell.Offset(i, 1).Value
Rtot = ActiveCell.Offset(i, 8).Value
If Odt & Oldgr & Otot <> Rdt & Rldgr & Rtot Then
ActiveCell.Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("A" & i).Select
End If
Next i
End Sub
However the code is not entering into For loop. Can someone please help me in sorting this out?
A sample copy is attached for ready reference.
Sub test()
Sheets("Original").Select
olrow = ActiveSheet.UsedRange.Rows.Count
Range("a1").Select
Sheets("revised").Select
rlrow = ActiveSheet.UsedRange.Rows.Count
Range("a1").Select
If olrow > rlrow Then
lastrow = olrow
Else
lastrow = rlow
End If
Sheets("Original").Select
Range("a1").Select
For i = 1 To lrow
Sheets("Original").Select
Range("a" & i).Select
Odt = ActiveCell.Offset(i, 0).Value
Oldgr = ActiveCell.Offset(i, 1).Value
Otot = ActiveCell.Offset(i, 8).Value
Sheets("revised").Select
Range("a" & i).Select
Rdt = ActiveCell.Offset(i, 0).Value
Rldgr = ActiveCell.Offset(i, 1).Value
Rtot = ActiveCell.Offset(i, 8).Value
If Odt & Oldgr & Otot <> Rdt & Rldgr & Rtot Then
ActiveCell.Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("A" & i).Select
End If
Next i
End Sub
However the code is not entering into For loop. Can someone please help me in sorting this out?
A sample copy is attached for ready reference.