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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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:
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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
Back
Top