答案 0 :(得分:0)
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