Extracting differences between two comma-separated strings

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon - I have two columns of comma-separated two character codes (for example):

Code:
A                                                           B
AA,DB,LN,WE,UR,TD,QW                         AA,LN,WE,VF,WE,UR,OW,ZL

The the codes will always comprise two characters, but will not necessarily be in alphabetical order.

In the next column, I need to create a comma-separated string comprising all the two digit codes from the first list that do NOT appear in the second.

So, in the above example, the third column will contain DB,TD

Do any of you fine folk have any suggestions of the best way in which I can accomplish this?

Thanks in advance

Pete
 
Last edited:
Try this, seems to work !!
Rich (BB code):
Function nStr(R1 As String, R2 As String) As String
Dim Sp As Variant, n As Long
Sp = Split(R1, ",")
For n = 0 To UBound(Sp)
    If InStr(R2, Sp(n)) > 0 Then
        nStr = nStr & IIf(nStr = "", Sp(n), "," & Sp(n))
    End If
Next n
End Function
Regards Mick
 
Last edited by a moderator:
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Just to show I'm not being lazy, I came up with this:
Code:
Function WhatsCommon(a As String, b As String) As String
    Dim i As Long
    Dim MyString As String
    Dim MySplit As Variant
    
    MySplit = Split(b, ",")
    
    For i = 0 To UBound(MySplit)
        If InStr(a, MySplit(i)) > 0 Then
            MyString = MyString & IIf(MyString = "", MySplit(i), "," & MySplit(i))
        End If
    Next i
    WhatsCommon = MyString
End Function

P.S - I didn't copy, Mick, honestly! - Thank you, too!
 
Last edited:
Upvote 0
Here's my reworking of Fluff's original function to identify uniques, using the same nomenclature, too:
Code:
Function WhatsUnique(a As String, b As String) As String
   Dim i As Long
   Dim Asplit As Variant
   Dim Bsplit As Variant
   
   Asplit = Split(a, ",")
   Bsplit = Split(b, ",")
   
   For i = 0 To UBound(Bsplit)
      Asplit = Filter(Asplit, Bsplit(i), False, vbTextCompare)
   Next i
   WhatsUnique = Join(Asplit, ",")
End Function

To all who helped, thank you and have a great weekend!

Pete
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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