Extracting similar words

Milade8080

New Member
Joined
Mar 13, 2014
Messages
25
Hi
Is there a way to make it possible to extract the same words between two sentences
For example, in cell A1 we have : My name is Morteza Ghovati
in cell B1 we have : Morteza Ghovati is My brother
That result is in cell C1 : My-is-Morteza-Ghovati
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Are you interested in a formula solution where the common words are collected in C, as you requested, but some helper columns are also used right to column C?
 
Upvote 0
For example, in cell A1 we have : My name is Morteza Ghovati
in cell B1 we have : Morteza Ghovati is My brother
That result is in cell C1 : My-is-Morteza-Ghovati
Give this UDF (user defined function) a try...
Code:
Function DupeWords(S1 As String, ByVal S2 As String) As String
  Dim X As Long, Words() As String
  Words = Split(S1)
  S2 = " " & S2 & " "
  For X = 0 To UBound(Words)
    If InStr(1, S2, " " & Words(X) & " ", vbTextCompare) Then
      DupeWords = DupeWords & "-" & Words(X)
    End If
  Next
  DupeWords = Mid(DupeWords, 2)
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use DupeWords just like it was a built-in Excel function. For example,

=DupeWords(A1,B1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Give this UDF (user defined function) a try...
Code:
Function DupeWords(S1 As String, ByVal S2 As String) As String
  Dim X As Long, Words() As String
  Words = Split(S1)
  S2 = " " & S2 & " "
  For X = 0 To UBound(Words)
    If InStr(1, S2, " " & Words(X) & " ", vbTextCompare) Then
      DupeWords = DupeWords & "-" & Words(X)
    End If
  Next
  DupeWords = Mid(DupeWords, 2)
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use DupeWords just like it was a built-in Excel function. For example,

=DupeWords(A1,B1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
Thanks for answer
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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