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?
 
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.


Book1
ABCD
1Main TextRevised CellAdded Text to Main by revised cellRemoved Text from Main by revised cell
2Washington was born into the provincial gentry of Colonial Virginia to a family of wealthy planters who owned tobacco plantations and slaves, which he inheritedWashington 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 youthIn his youthplantations
3The amount of military detail handled personally by the President in wartime has varied dramaticallyThe amount of military detail handled personally by the President in wartime has varied dramaticallyNO CHANGENO CHANGE
4The Department of Defense is headed by the Secretary of Defense, a cabinet-level head who reports directly to the President of the United StatesThe DOD is headed by the Secretary of Defense, a cabinet-level head who reports directly to the President of the United StatesDODDepartment of Defense
Sheet1





eF6AXw
 
Last edited:
Upvote 0

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
sorry for bumping an old thread. Does anyone know how to edit the original vba to make this formula to include case sensitive characters?

IE:

A1: My Company, LLC
A2: My Company, Llc
A3: Llc
 
Upvote 0
sorry for bumping an old thread. Does anyone know how to edit the original vba to make this formula to include case sensitive characters?

IE:

A1: My Company, LLC
A2: My Company, Llc
A3: Llc
For my code, change the two instances of vbTextCompare to vbBinaryCompare and I think that should work.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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