This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

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

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
```

```
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
```

=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,

Thomas

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

```
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
```

Diff-1-.xls
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

```
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
```

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Diff-v2.xls