VBA Help!

jd556

New Member
Joined
Apr 17, 2013
Messages
2
I need to create a function that checks two arrays and finds the Unique names from both and prints it.

SO
Columns
A B
Joe Joe
Moe Moe
Alex John
Matt Matt

And my function =unique(A1:A4, B1:B4) should equal Alex, John

I have this but it is not working :(
Function Uniques(astrArray1() As String, astrArray2() As String) As String
'You probably want to add code here
Dim i As Long
Dim o As Long


For i = LBound(astrArray1) To UBound(astrArray1)
If astrArray1(i) <> astrArray2(i) Then
findUniques = findUniques & astrArray1(i) & ","
End If
Next


For o = LBound(astrArray2) To UBound(astrArray2)
If astrArray1(o) <> astrArray2(o) Then
findUniques = findUniques & astrArray2(o) & ","
End If
Next o

Any help is greatly appreciated!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,883
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try this:
Code:
Function Unique(R1 As Range, R2 As Range) As String
Dim c As Range
For Each c In R1
    If Application.CountIf(R2, c.Value) = 0 Then
        Unique = Unique & ", " & c.Value
    End If
Next c
For Each c In R2
    If Application.CountIf(R1, c.Value) = 0 Then
        Unique = Unique & ", " & c.Value
    End If
Next c
Unique = Right(Unique, Len(Unique) - 2)
End Function
Example of use (entered in a cell):
=Unique(A1:A4,B1:B4)
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,469
Messages
5,831,829
Members
430,088
Latest member
Caeinlb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top