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.

[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 652"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]7KANWTF[/TD]
[TD]7COAWTF[/TD]
[TD]KAN[/TD]
[/TR]
[TR]
[TD]7WTNWTF[/TD]
[TD]7COAWTF[/TD]
[TD]WTN[/TD]
[/TR]
[TR]
[TD]7NEBWTF[/TD]
[TD]7COAWTF[/TD]
[TD]NEB[/TD]
[/TR]
[TR]
[TD]7SFLWTF[/TD]
[TD]7COAWTF[/TD]
[TD]SFL[/TD]
[/TR]
[TR]
[TD]7RUTWTF[/TD]
[TD]7COAWTF[/TD]
[TD]RUT[/TD]
[/TR]
[TR]
[TD]7LOUWTF[/TD]
[TD]7COAWTF[/TD]
[TD]LOU[/TD]
[/TR]
[TR]
[TD]7MIAWTF[/TD]
[TD]7COAWTF[/TD]
[TD]MIA[/TD]
[/TR]
[TR]
[TD]7TAMWTF[/TD]
[TD]7COAWTF[/TD]
[TD]TAM[/TD]
[/TR]
[TR]
[TD]7NCSWTF[/TD]
[TD]7COAWTF[/TD]
[TD]NCS[/TD]
[/TR]
[TR]
[TD]7GATWTF[/TD]
[TD]7COAWTF[/TD]
[TD]GAT[/TD]
[/TR]
[TR]
[TD]7ASUWTF[/TD]
[TD]7COAWTF[/TD]
[TD]ASU[/TD]
[/TR]
[TR]
[TD]7ECAWTF[/TD]
[TD]7COAWTF[/TD]
[TD]ECA[/TD]
[/TR]
[TR]
[TD]7INDWTF[/TD]
[TD]7COAWTF[/TD]
[TD]IND[/TD]
[/TR]
[TR]
[TD]7MSSWTF[/TD]
[TD]7COAWTF[/TD]
[TD]MSS[/TD]
[/TR]
[TR]
[TD]7KANWTF[/TD]
[TD]7COAWTF[/TD]
[TD]KAN[/TD]
[/TR]
[TR]
[TD]7KANWTF[/TD]
[TD]7COAWTF[/TD]
[TD]KAN[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
@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
[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#70AD47]raw[/td][td=bgcolor:#70AD47]string[/td][td=bgcolor:#70AD47]result[/td][td=bgcolor:#70AD47]result2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7KANWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]KAN[/td][td=bgcolor:#E2EFDA]KAN[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7WTNWTF[/td][td]7COAWTF[/td][td]N[/td][td]WTN[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7NEBWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]NEB[/td][td=bgcolor:#E2EFDA]NEB[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7SFLWTF[/td][td]7COAWTF[/td][td]SFL[/td][td]SFL[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7RUTWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]RU[/td][td=bgcolor:#E2EFDA]RUT[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7LOUWTF[/td][td]7COAWTF[/td][td]LOU[/td][td]LOU[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7MIAWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]MI[/td][td=bgcolor:#E2EFDA]MIA[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7TAMWTF[/td][td]7COAWTF[/td][td]M[/td][td]TAM[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7NCSWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]NCS[/td][td=bgcolor:#E2EFDA]NCS[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7GATWTF[/td][td]7COAWTF[/td][td]G[/td][td]GAT[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7ASUWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]SU[/td][td=bgcolor:#E2EFDA]ASU[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7ECAWTF[/td][td]7COAWTF[/td][td]E[/td][td]ECA[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7INDWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]IND[/td][td=bgcolor:#E2EFDA]IND[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7MSSWTF[/td][td]7COAWTF[/td][td]MSS[/td][td]MSS[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]7KANWTF[/td][td=bgcolor:#E2EFDA]7COAWTF[/td][td=bgcolor:#E2EFDA]KAN[/td][td=bgcolor:#E2EFDA]KAN[/td][/tr]

[tr=bgcolor:#FFFFFF][td]7KANWTF[/td][td]7COAWTF[/td][td]KAN[/td][td]KAN[/td][/tr]
[/table]


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,223,933
Messages
6,175,476
Members
452,646
Latest member
tudou

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