Important Union Intersect VBA Problems

  • Thread starter SADEQ AHMAD CHOWDHURY
  • Start date
S

SADEQ AHMAD CHOWDHURY

The Scenerio:
Set A = 1,2,3,4,5 (lets the numbers are in E2 to I2)
Set B = 1,2,6,7,8 (lets the numbers are in E3 to I3)

Now how to find the following problems:
1. Set A union set B in cell A10 (i.e in A10 cell the numbers should
be 1, 2, 3, 4, 5, 6, 7, 8)
2. Set A Intersection Set B in cell A11 (i.e. in A11 cell the numbers
should be 1, 2)
3. Uncommon numbers between Set A and Set B in cell A12 (i.e. in A12
cell the numbers should be 3, 4, 5, 6, 7, 8)

Could anyone can help me to solve this problem?

Thanks
Sadi
 
J

James Ravenswood

The Scenerio:
Set A = 1,2,3,4,5 (lets the numbers are in E2 to I2)
Set B = 1,2,6,7,8 (lets the numbers are in E3 to I3)

Now how to find the following problems:
1. Set A union set B in cell A10 (i.e in A10 cell the numbers should
be 1, 2, 3, 4, 5, 6, 7, 8)
2. Set A Intersection Set B in cell A11 (i.e. in A11 cell the numbers
should be 1, 2)
3. Uncommon numbers between Set A and Set B in cell A12 (i.e. in A12
cell the numbers should be 3, 4, 5, 6, 7, 8)

Could anyone can help me to solve this problem?

Thanks
Sadi

Give this a try:

Sub cutaneous()
Dim A As Range, B As Range, C As Range
Dim A10 As Range, A11 As Range
Set A = Range("E2:I2")
Set B = Range("E3:I3")
Set C = Union(A, B)
Set A10 = Range("A10")
Set A11 = Range("A11")
A10 = ""
A11 = ""
Dim coll As Collection
Set coll = New Collection
On Error Resume Next
For Each r In C
v = r.Value
coll.Add v, CStr(v)
If Err.Number = 0 Then
A10.Value = A10.Value & "," & v
Else
A11.Value = A11.Value & "," & v
Err.Number = 0
End If
Next
v10 = A10.Value
v11 = A11.Value
A10.Value = Right(v10, Len(v10) - 1)
A11.Value = Right(v11, Len(v11) - 1)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top