Compare two strings, and find difference?

EtherBoo

New Member
Joined
Oct 26, 2006
Messages
37
This may not be possible with excel, but this is what I'm trying to do

A1 = Hello John, my name is Steve, how was your day?
B1 = Hello John, my name is Steve, was day?

I need C1 to return:
how your

Is this possible?
 

flora1

New Member
Joined
Nov 27, 2017
Messages
48
Here is my corrected code... it should work correctly now.
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function Differences(ByVal Str1 As String, ByVal Str2 As String) As String
  Dim Temp As String, Arr1 As Variant, Arr2 As Variant, Var As Variant
  Arr1 = Split(Application.Trim(Replace(Str1, ",", " ")))
  Arr2 = Split(Application.Trim(Replace(Str2, ",", " ")))
  If UBound(Arr2) > UBound(Arr1) Then
    Str2 = " " & Application.Trim(Replace(Str2, ",", " ")) & " "
    For Each Var In Arr1
      Str2 = Replace(Str2, " " & Var & " ", "  ", , , vbTextCompare)
    Next
    Differences = Replace(Application.Trim(Str2), " ", ", ")
  Else
    Str1 = " " & Application.Trim(Replace(Str1, ",", " ")) & " "
    For Each Var In Arr2
      Str1 = Replace(Str1, " " & Var & " ", "  ", , , vbTextCompare)
    Next
    Differences = Replace(Application.Trim(Str1), " ", ", ")
  End If
End Function[/TD]
[/TR]
</tbody>[/TABLE]


Dear Rick,

I was trying your cool UDF with my data and wanted to return values in Column C and Column D but somehow it did not work.

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style="text-align: center;;">Main Text</td><td style="text-align: center;;">Revised Cell</td><td style="text-align: center;;">Added Text to Main by revised cell</td><td style="text-align: center;;">Removed Text from Main by revised cell</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style="text-align: center;;">Washington was born into the provincial gentry of Colonial Virginia to a family of wealthy planters who owned tobacco plantations and slaves, which he inherited</td><td style="text-align: center;;">Washington was born into the provincial gentry of Colonial Virginia to a family of wealthy planters who owned tobacco and slaves, which he inherited In his youth</td><td style="text-align: center;color: #7030A0;;">In his youth</td><td style="text-align: center;color: #FF0000;;">plantations</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style="text-align: center;;">The amount of military detail handled personally by the President in wartime has varied dramatically</td><td style="text-align: center;;">The amount of military detail handled personally by the President in wartime has varied dramatically</td><td style="text-align: center;color: #FF0000;;">NO CHANGE</td><td style="text-align: center;color: #FF0000;;">NO CHANGE</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: center;;">The Department of Defense is headed by the Secretary of Defense, a cabinet-level head who reports directly to the President of the United States</td><td style="text-align: center;;">The DOD is headed by the Secretary of Defense, a cabinet-level head who reports directly to the President of the United States</td><td style="text-align: center;color: #FF0000;;">DOD</td><td style="text-align: center;color: #FF0000;;">Department of Defense</td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet1</p><br /><br />




 
Last edited:

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Watch MrExcel Video

Forum statistics

Threads
1,108,938
Messages
5,525,735
Members
409,661
Latest member
pprabha

This Week's Hot Topics

Top