*=TextDif(A2,B2)*

TextDif is an UDF, like this:

Function TextDif(S1 As String, S2 As String) As String
   Dim Arr1, Arr2
   Dim n As Integer, i As Integer, t As String

   Arr1 = Split(S1, ","): Arr2 = Split(S2, ",")

   For i = LBound(Arr2) To UBound(Arr2)
      For n = LBound(Arr1) To UBound(Arr1)
         If Arr1(n) = Arr2(i) Then Arr2(i) = ""
      Next n
   Next i

   For i = LBound(Arr2) To UBound(Arr2)
      If Len(Arr2(i)) > 0 Then t = t & Arr2(i) & ","
   Next i

   TextDif = t
   If Len(t) > 0 Then TextDif = Left(t, Len(t) - 1)
End Function




On Fri, Apr 8, 2011 at 4:46 AM, SHC <stuart.hallcoo...@googlemail.com>wrote:

> I'd like a function script that compares the strings from two cells,
> and returns, in a third cell, the parts of the 2nd string that do not
> match parts of the 1st string (I don't need to return the parts of 1st
> string that do not match parts of the 2nd string).
>
> Examples:
> Cell1: Chris
> Cell2: Carl,Chris,Peter
> Result in Cell3: Carl,Peter
>
> Cell1: Chris,Carl
> Cell2: Carl,Peter,Chris
> Result in Cell3: Peter
>
> Cell1: Chris,Dave
> Cell2: Carl,Chris,Peter
> Result: Carl,Peter
>
> Cell1: Chris,Dave,Peter,Carl
> Cell2: Dave,Chris,Carl
> Cell3 is empty
>
> Note, parts of the strings (separated by commas) will not necessarily
> be in the same order.
>
> Any help would be most appreciated
>
> Thanks.
>
>

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Attachment: ctv_TextDif about Chris and Peter.xls
Description: MS-Excel spreadsheet

Reply via email to