COMPARECELLS

COMPARECELLS(rgeOne, rgeTwo)
Returns the

rgeOne
rgeTwo

REMARKS
Public Function COMPARECELLS( _

Public Function COMPARECELLS( _ 
         ByVal rgeOne As Range, _
         ByVal rgeTwo As Range) _
         As String

Dim lcellcount As Long
Dim rgeCellOne As Range
Dim rgeCellTwo As Range
Dim sDifferentConCat As String
   
'assuming the number of rows and columns are the same in both ranges
   
   For lcellcount = 1 To rgeOne.Cells.Count
      Set rgeCellOne = rgeOne.Cells(lcellcount)
      Set rgeCellTwo = rgeTwo.Cells(lcellcount)
      
      If (rgeCellOne.Value <> rgeCellTwo.Value) Then
          sDifferentConCat = sDifferentConCat & "," & rgeCellOne.Address(False, False)
      End If
       
   Next lcellcount
   
   If (Len(sDifferentConCat) = 0) Then
      COMPARECELLS = "identical"
   Else
      sDifferentConCat = Right(sDifferentConCat, Len(sDifferentConCat) - 1)
      COMPARECELLS = sDifferentConCat
   End If

End Function

For instructions on how to add this function to a workbook refer to the page under Inserting Functions


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext