VBA for comparing values in two columns and removing duplicate information

Mike_Gr

New Member
Joined
Nov 14, 2012
Messages
15
Hi!
I'm trying to figure out a smart way of comparing text strings in two columns and returning the values that are unique for column B in column C. The order of the values is random and superfluous commas and spaces need to be removed (no commas occur within the individual values).
All help is greatly appreciated!


A
B
C
chocolate, strawberry
banana, chocolate, strawberry
banana
vanilla, blueberry
licorice, raspberry, vanilla, fudge, blueberry
licorice, raspberry, fudge

<tbody>
</tbody>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Assuming that your data started in A1 to B2. Formula goes in C2. Remember to use shift-ctrl-enter. You can now drag down C2 to fill remaining rows.

Code:
=INDIRECT(TEXT(MIN(IF(($A$2:$B$3<>"")*(COUNTIF($C$1:C1,$A$2:$B$3)=0),ROW($2:$3)*100+COLUMN($A:$B),7^8)),"R0C00"),)&""
 
Upvote 0
Sorry this is not what you wanted. I will keep looking
 
Upvote 0
I can do this via VBa not formula at the moment.
 
Upvote 0
Got to say this one has me stumped! I found a supposed way to do it with TEXTJOIN but we do not have that available (good old Microsoft not issuing an update to existing 2016 users). Any other Excel guru's can help?
 
Upvote 0
How about
Code:
Function MikeGr(St1 As String, St2 As String) As String
   Dim Sp As Variant
   Dim i As Long
   Sp = Split(St2, ",")
   With CreateObject("scripting.dictionary")
      .CompareMode = 1
      For i = 0 To UBound(Sp)
         If Not Trim(Sp(i)) = "" Then .Item(Trim(Sp(i))) = Empty
      Next i
      Sp = Split(St1, ",")
      For i = 0 To UBound(Sp)
         If .Exists(Trim(Sp(i))) Then .Remove Trim(Sp(i))
      Next i
      MikeGr = Join(.keys, ", ")
   End With
End Function
Used like =MikeGr(A2,B2)
 
Upvote 0
How about
Code:
Function MikeGr(St1 As String, St2 As String) As String
   Dim Sp As Variant
   Dim i As Long
   Sp = Split(St2, ",")
   With CreateObject("scripting.dictionary")
      .CompareMode = 1
      For i = 0 To UBound(Sp)
         If Not Trim(Sp(i)) = "" Then .Item(Trim(Sp(i))) = Empty
      Next i
      Sp = Split(St1, ",")
      For i = 0 To UBound(Sp)
         If .Exists(Trim(Sp(i))) Then .Remove Trim(Sp(i))
      Next i
      MikeGr = Join(.keys, ", ")
   End With
End Function
Used like =MikeGr(A2,B2)

The aim is to do it via formula. I can do a single value searching a comma separated cell but not a coma separated cell searching another.
 
Upvote 0
Where do you get that from?
The title clearly states VBA

Gaaah, my bad! :eek: Could have sworn that a formula was wanted. I could have done the VBa ages ago. Must admit it is quite the challenge to do it via a formula and keep it to one cell.
 
Upvote 0

Forum statistics

Threads
1,215,875
Messages
6,127,477
Members
449,385
Latest member
KMGLarson

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