Formula or script that can find difference between 2 colums . the data between each coma has to be queried.

Hi,

Formula or script that can find difference between 2 colums . the data between each coma has to be queried.
Attached a sample. I want to check whats the email thats single and does not have a match in the other colum.

Regards
sharath

Diff.xls
LVL 11
bsharathAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nutschCommented:
Hi Sharath,

You can use the following udf, assuming that there is only one single non-matching e-mail in your list.

Thomas

Function diffMail(str1 As String, str2 As String)
Dim arr1, arr2
Dim i As Long, j As Long
arr1 = Split(str1, ",")
arr2 = Split(str2, ",")

For i = 0 To UBound(arr1)
    For j = 0 To UBound(arr2)
        If arr2(j) = arr1(i) Then GoTo nxti
    Next j
    diffMail = arr1(i)
    Exit Function
nxti:
Next i

For i = 0 To UBound(arr2)
    For j = 0 To UBound(arr1)
        If arr1(j) = arr2(i) Then GoTo nxti2
    Next j
    diffMail = arr2(i)
    Exit Function
nxti2:
Next i

End Function

Open in new window

0
bsharathAuthor Commented:
I will have 1 to 100's of email id's that will not match
0
nutschCommented:
This update should take everything you throw at it


Function diffMail(str1 As String, str2 As String)
Dim arr1, arr2
Dim i As Long, j As Long
arr1 = Split(str1, ",")
arr2 = Split(str2, ",")

For i = 0 To UBound(arr1)
    For j = 0 To UBound(arr2)
        If arr2(j) = arr1(i) Then GoTo nxti
    Next j
    diffMail = diffMail & "," & arr1(i)
nxti:
Next i

For i = 0 To UBound(arr2)
    For j = 0 To UBound(arr1)
        If arr1(j) = arr2(i) Then GoTo nxti2
    Next j
    diffMail = diffMail & "," & arr2(i)
nxti2:
Next i

diffMail = Right(diffMail, Len(diffMail) - 1)

End Function

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

bsharathAuthor Commented:
How should i run this. Is it a macro?
0
nutschCommented:
It's a user defined function. You copy it in a module just like a macro and you call it from the worksheet. In your case, in cell J2, you'd use the following formula, then copy down.

 =diffMail(D2,E2)

Warning. If you put the code in a personal macro workbook, you'll have to call the function with the name of that workbook, as in
 =personal.xls!diffMail(D2,E2)

Thomas

0
bsharathAuthor Commented:
thanks its perfetc
Some cases both or any 1 will have empty cells in the colum. Can i not get
#VALUE!
Can i get them blank if both nil or 1 cell is nil
0
TracyVBA DeveloperCommented:
You can also try this.  It's a macro called FindDifferences.  It will find the differences for as many rows as you have and it will enter the difference in column J.  
Sub FindDifferences()

    Dim myValue1 As String 'email1 Value from Column D
    Dim myValue2 As String 'email1 Value from Column E
    Dim emailArray1 As Variant 'Holds email1s from myValue1 (Column D)
    Dim emailArray2 As Variant 'Holds email1s from myValue2 (Column E)
    Dim blnMatch As Boolean
    Dim lastRow As Long
    Dim i As Long
    Dim p As Long
    Dim k As Long
    
    
    lastRow = Range("D" & Rows.Count).End(xlUp).Row
    For k = 2 To lastRow
    
        blnMatch = False
        Cells(k, 10).Value = "" 'Clear out difference
    
        myValue1 = Cells(k, "D").Value
        emailArray1 = Split(myValue1, ",")
        For i = 0 To UBound(emailArray1)
           Debug.Print emailArray1(i)
        Next i
    
        myValue2 = Cells(k, "E").Value
        emailArray2 = Split(myValue2, ",")
        For i = 0 To UBound(emailArray2)
           Debug.Print emailArray2(i)
        Next i
    
        For i = 0 To UBound(emailArray1)
            For p = 0 To UBound(emailArray2)
                If emailArray1(i) = emailArray2(p) Then
                    'Match
                    blnMatch = True
                    Exit For
                Else
                End If
            Next p
    
            If blnMatch = False Then
                'Add to Diff in Column J
                If Len(Cells(k, 10).Value) > 1 Then
                    'Add to existing values
                    Cells(k, 10).Value = Cells(k, 10).Value & ", " & emailArray1(i)
                Else
                    'First value added
                    Cells(k, 10).Value = emailArray1(i)
                End If
            Else
                'Reset bool to false
                blnMatch = False
            End If
            
        Next i
        
        If Len(Cells(k, 10).Value) = 0 Then
            Cells(k, 10).Value = "No Difference"
        Else
        End If
        
    Next k

End Sub

Open in new window

Diff-1-.xls
0
bsharathAuthor Commented:
broomee9
thanks Script works but it gets just the D drive different with E into J and not E's difference. Can i get the E mismatch to K
0
TracyVBA DeveloperCommented:
Attached is the amended version which pulls the differences out of both D and E.
Diff-v2.xls
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nutschCommented:
Here is an update that will take care of blank cells.



Function diffMail(str1 As String, str2 As String)
if str1="" then 
diffmail=str2
exit function
end if

if str2="" then 
diffmail=str1
exit function
end if


Dim arr1, arr2
Dim i As Long, j As Long
arr1 = Split(str1, ",")
arr2 = Split(str2, ",")

For i = 0 To UBound(arr1)
    For j = 0 To UBound(arr2)
        If arr2(j) = arr1(i) Then GoTo nxti
    Next j
    diffMail = diffMail & "," & arr1(i)
nxti:
Next i

For i = 0 To UBound(arr2)
    For j = 0 To UBound(arr1)
        If arr1(j) = arr2(i) Then GoTo nxti2
    Next j
    diffMail = diffMail & "," & arr2(i)
nxti2:
Next i

diffMail = Right(diffMail, Len(diffMail) - 1)

End Function

Open in new window

0
bsharathAuthor Commented:
Thank you
Can you help with this related post
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_25976948.html
need to get the difference in 2 different colums so i know the difference is from which colum
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.