COMPARECELLS



Remarks

* For instructions on how to add a function to a workbook refer to the page under Inserting Functions
* The equivalent JavaScript function is 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


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