Sub Highlight()
Dim RSource As Range, RTarget As Range, RTest As Range
' must properly qualify Cells()
Set RSource = ActiveWorkbook.Worksheets("Sheet1").Range( _
ActiveWorkbook.Worksheets("Sheet1").Cells(1, 1), _
ActiveWorkbook.Worksheets("Sheet1").Cells(100, 42))
' not strictly needed ... could be as small as Set RTarget = ActiveWorkbook.Worksheets("Sheet2").[A1]
Set RTarget = ActiveWorkbook.Worksheets("Sheet2").Range( _
ActiveWorkbook.Worksheets("Sheet2").Cells(1, 1), _
ActiveWorkbook.Worksheets("Sheet2").Cells(100, 42))
For Each RTest In RSource.Cells
If RTest <> RTarget.Cells(RTest.Row, RTest.Column) Then
' make them red
RTest.Interior.Color = vbRed
RTarget.Cells(RTest.Row, RTest.Column).Interior.Color = vbRed
Else
' make them white
RTest.Interior.Color = vbWhite
RTarget.Cells(RTest.Row, RTest.Column).Interior.Color = vbWhite
End If
Next RTest
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.