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!


[TABLE="class: grid, width: 600"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]chocolate, strawberry
[/TD]
[TD]banana, chocolate, strawberry
[/TD]
[TD]banana
[/TD]
[/TR]
[TR]
[TD]vanilla, blueberry
[/TD]
[TD]licorice, raspberry, vanilla, fudge, blueberry
[/TD]
[TD]licorice, raspberry, fudge
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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! :eeek: 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,224,823
Messages
6,181,178
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