COMPARECELLS

COMPARECELLS(rgeOne, rgeTwo)
Returns a description of whether two ranges are identical or not.

rgeOne
rgeTwo

REMARKS
??

 A
1test

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

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