How find elements NOT common to two ranges?
Chet,
Sub FindUniqueElements()
Dim myC As Range
Dim rngA As Range
Dim rngB As Range
Dim myVals() As Variant
Dim myCount As Integer
Dim Msg As String
Set rngA = Range("A1:A3")
Set rngB = Range("B1:B3")
myCount = 0
For Each myC In rngA
If IsError(Application.Match(myC, rngB, False)) Then
myCount = myCount + 1
ReDim Preserve myVals(1 To myCount)
myVals(myCount) = myC.Value
End If
Next myC
For Each myC In rngB
If IsError(Application.Match(myC, rngA, False)) Then
myCount = myCount + 1
ReDim Preserve myVals(1 To myCount)
myVals(myCount) = myC.Value
End If
Next myC
Msg = ""
For myCount = 1 To UBound(myVals)
Msg = Msg & myVals(myCount) & Chr(10)
Next myCount
MsgBox Msg
End Sub
HTH,
Bernie
MS Excel MVP
"Chet" wrote in message
...
Can someone help me with some code to give me the elements of two
ranges which are the NOT common to both ranges. In other words rngA
is blue white red, and rngB is blue white yellow. The outcome of the
code would give the two elements which are not in common to the two
ranges (red, yellow) since blue and white are in both ranges.
Thanks, Chet
|