View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Aviashn Aviashn is offline
external usenet poster
 
Posts: 17
Default How to compare two differnet cell ranges to see if they are thesa

I know this has been answered, however, an alternate solution that
accounts for different workbooks, ranges, or relative positions is
below. Another benefit is that it only takes one cell. Just enter as
a normal function in any cell.

I'd appreciate any comments as I've never attempted to solve this
problem before.

Public Function CompareTwoRanges(rOne As Range, rTwo As Range) As
String

Dim lRdiff As Long
Dim lCdiff As Long
Dim arOne As Variant
Dim arTwo As Variant
Dim rCell As Range

If rOne.Row rTwo.Row Then
lRdiff = rOne.Row - rTwo.Row

Else
lRdiff = rTwo.Row - rOne.Row
End If

If rOne.Column rTwo.Column Then
lCdiff = rOne.Column - rTwo.Column

Else
lCdiff = rTwo.Column - rOne.Column
End If
CompareTwoRanges = "They match."

For Each rCell In rOne
If rCell.Value < rTwo.Parent.Cells(rCell.Row + lRdiff,
rCell.Column + lCdiff).Value Then
CompareTwoRanges = "Discrepancies Exist."
Exit Function
End If
Next rCell

End Function

On Jan 16, 10:32*am, Tom wrote:
I have two *data charts on the same worksheet *with each chart containing 14
columns and 79 rows. Is there a way to compare the two cell by cell and then
output a "same" or "different" if and cell in the a row is different between
the two data charts? Does this have to be done cell by cell or can it be done
by ranges?