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!
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,819
Messages
5,598,293
Members
414,223
Latest member
Accountant2B

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