How do I check if one range is exactly the same as another?
This didn't work:
[VBA]if aRange = anotherRange then[/VBA]
So I've been using:
[VBA]if aRange.address = anotherRange.address then[/VBA]
Is that correct?
How do I check if one range is exactly the same as another?
This didn't work:
[VBA]if aRange = anotherRange then[/VBA]
So I've been using:
[VBA]if aRange.address = anotherRange.address then[/VBA]
Is that correct?
It's one way, but be careful.
This
[vba]
Dim aRange As Range
Dim anotherRange As Range
Set aRange = Range("Sheet1!A1:A10")
Set anotherRange = Range("Sheet2!A1:A10")
MsgBox aRange.Address = anotherRange.Address
[/vba]
shows true, when it isn't. But this,
[vba]
MsgBox aRange.Address(, , , True) = anotherRange.Address(, , , True)
[/vba]
is better.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
OK, I see.
Cheers
This returns
False
True
[VBA]Sub test()
Dim aRange As Range, bRange As Range
Set aRange = Range("A1:A10")
Set bRange = Range(Cells(1, 1), Cells(10, 1))
MsgBox (aRange Is bRange) & vbCr & (aRange.Address(, , , True) = bRange.Address(, , , True))
End Sub[/VBA]
I've always assumed that the False is the result of a glitch in VBA. Is that correct?