compare text in two columns and return the difference in a third

adipric

New Member
Joined
Jun 5, 2019
Messages
1
I am needing to compare two columns and have the third be the result what is different, keeping the characters from the first column. It cannot be based off of left or right because there are values (not in the example) where the different characters will be in different places. I need the result to look like the below example.

7KANWTF7COAWTFKAN
7WTNWTF7COAWTFWTN
7NEBWTF7COAWTFNEB
7SFLWTF7COAWTFSFL
7RUTWTF7COAWTFRUT
7LOUWTF7COAWTFLOU
7MIAWTF7COAWTFMIA
7TAMWTF7COAWTFTAM
7NCSWTF7COAWTFNCS
7GATWTF7COAWTFGAT
7ASUWTF7COAWTFASU
7ECAWTF7COAWTFECA
7INDWTF7COAWTFIND
7MSSWTF7COAWTFMSS
7KANWTF7COAWTFKAN
7KANWTF7COAWTFKAN

<colgroup><col><col><col></colgroup><tbody>
</tbody>


<tbody>
</tbody>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
@adipric

Is the string length constant at 7 characters?
Is it always 3 consecutive different characters?
 
Last edited:
Upvote 0
you said this is not representative example
so maybe with PowerQuery
rawstringresultresult2
7KANWTF7COAWTFKANKAN
7WTNWTF7COAWTFNWTN
7NEBWTF7COAWTFNEBNEB
7SFLWTF7COAWTFSFLSFL
7RUTWTF7COAWTFRURUT
7LOUWTF7COAWTFLOULOU
7MIAWTF7COAWTFMIMIA
7TAMWTF7COAWTFMTAM
7NCSWTF7COAWTFNCSNCS
7GATWTF7COAWTFGGAT
7ASUWTF7COAWTFSUASU
7ECAWTF7COAWTFEECA
7INDWTF7COAWTFINDIND
7MSSWTF7COAWTFMSSMSS
7KANWTF7COAWTFKANKAN
7KANWTF7COAWTFKANKAN

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    C2R = Table.AddColumn(Source, "result", each Text.Trim([raw],{"7","C","O","A","W","T","F"})),
    TBD = Table.AddColumn(C2R, "Text Between Delimiters", each Text.BetweenDelimiters([raw], "7", "WTF"), type text),
    Rename = Table.RenameColumns(TBD,{{"Text Between Delimiters", "result2"}})
in
    Rename[/SIZE]

1st result: all characters from string column are removed from raw column
2nd result I did with a pattern: characters to remove: 1st and 3 last (in this case column string is not necessary)
 
Last edited:
Upvote 0
Hi,

What version of Excel is this for?

Also, why is MIA the result for:

7MIAWTF 7COAWTF

?

Only the letters in positions 2 and 3 differ, not that in position 4.

Similarly for your result of ECA for:

7ECAWTF 7COAWTF


Regards
 
Upvote 0
This might suit if the different characters are always consecutive.


Excel 2010
ABC
27KANWTF7COAWTFKAN
37WTNWTF7COAWTFWTN
47NEBWTF7COAWTFNEB
57SFLWTF7COAWTFSFL
67RUTWTF7COAWTFRUT
77LOUWTF7COAWTFLO
87MIAWTF7COAWTFMI
97TAMWTF7COAWTFTAM
107NCSWTF7COAWTFNCS
117GATWTF7COAWTFGAT
127ASUWTF7COAWTFASU
137ECAWTF7COAWTFEC
147INDWTF7COAWTFIND
157MSSWTF7COAWTFMSS
167KANWTF7COAWTFKAN
177KANWTF7COAWTFKAN
187XXAWTF7XMAWTFX
Sheet14
Cell Formulas
RangeFormula
C2=IFERROR(MID(A2,MATCH(FALSE,MID(A2,{1,2,3,4,5,6,7},1)=MID(B2,{1,2,3,4,5,6,7},1),0),SUMPRODUCT((MID(A2,{1,2,3,4,5,6,7},1)<>MID(B2,{1,2,3,4,5,6,7},1))*1)),"")


I not consecutive then a simple user-defined function should sort it.

Code:
Function Diffs(Str1 As Range, Str2 As Range) As String
For i = 1 To 7
If Mid(Str1, i, 1) <> Mid(Str2, i, 1) Then Diffs = Diffs & Mid(Str1, i, 1)
Next i
End Function


Excel 2010
ABC
27KANWTF7COAWTFKAN
37WTNWTF7COAWTFWTN
47NEBWTF7N*B*T*EWF
Sheet14
Cell Formulas
RangeFormula
C2=Diffs(A2,B2)
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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