# VBA Help!

#### jd556

##### New Member
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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:

Replies
1
Views
284
Replies
1
Views
374
Replies
0
Views
199
Replies
0
Views
145
Replies
1
Views
132

1,212,148
Messages
6,106,246
Members
448,009
Latest member
Brgrant820

### 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?

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