View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Compare and Highlight Differences

Hi RyGuy,

I have edited you code to assign a second range on another sheet to a range
identical to the first sheet and then handled the comparison. Under limited
testing it appears to work satisfactorily.

Sub Compare2Shts()

Dim rRangePrimary As Range
Dim rRangeSecondary As Range
Dim wsPrimary As Worksheet
Dim wsSecondary As Worksheet
Dim strPrompt As String

Set wsPrimary = Sheets("Primary")
Set wsSecondary = Sheets("Secondary")

wsPrimary.Select

Set rRangePrimary = Nothing
strPrompt = "Please select a range for input."

Do
On Error Resume Next
Set rRangePrimary = Application.InputBox _
(Prompt:=strPrompt, _
Title:="SPECIFY RANGE", Type:=8)
On Error GoTo 0

If rRangePrimary Is Nothing Then
MsgBox "User cancelled. " & "Processing terminated"
Exit Sub
End If
Loop While rRangePrimary Is Nothing

Set rRangeSecondary = wsSecondary.Range(rRangePrimary.Address)

With rRangeSecondary
For i = 1 To .Rows.Count
If .Cells(i).Value < rRangePrimary.Cells(i).Value Then
.Cells(i).Interior.ColorIndex = 3
End If
Next i
End With

End Sub

Regards,

OssieMac