View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
[email protected] EagleOne@discussions.microsoft.com is offline
external usenet poster
 
Posts: 391
Default VBA code to ascertain difference between Range1 and Range2

Thanks for your knowledge and time!

"Rick Rothstein" wrote:

If I understand your question correctly, you want to select the cells in the
Union of Range1 and Range2 that lie outside of their Intersection. If that
is correct, something this should work for you...

' Calculate the union of the two ranges
' with their intersection omitted
Sub SelectDifference(R1 As Range, R2 As Range)
Dim I As Range, C As Range
Dim Difference As Range
Set I = Intersect(R1, R2)
For Each C In Union(R1, R2)
If Intersect(C, I) Is Nothing Then
If Difference Is Nothing Then
Set Difference = C
Else
Set Difference = Union(C, Difference)
End If
End If
Next
Difference.Select
End Function