Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/23811507/test-if-two-range-objects-refer-to-the-same-range

Note: My Function is much simpler, but served my purpose, in the SO post there is another longer/SLOWER function that will check cell contents.

Public Function RangeLengthsEqualBoolean(rngA As Range, rngB As Range) As Boolean
If rngA.Cells.Count = rngB.Cells.Count Then
 Debug.Print "Ranges are Equal"
 RangeLengthsEqualBoolean = True
Else
 Debug.Print "Ranges are NOT Equal"
 RangeLengthsEqualBoolean = False
End If
End Function
Public Sub Testings()

Dim rngA As Range, rngB As Range

Set rngA = Range("A1:A10")
Set rngB = Range("A1:A10")
'Set rngB = Range("A2:A10")

Dim RangeComparision As Boolean
RangeComparison = RangeLengthsEqualBoolean(rngA, rngB)
Debug.Print RangeComparison

End Sub
  • No labels