How to Capture multiple Keywords in paragraph

mrcris

New Member
Joined
Oct 31, 2018
Messages
9
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]keyword[/TD]
[TD]paragraph[/TD]
[TD]Expected Result[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Lorem[/TD]
[TD]Lorem ipsum dolor sit amet, consectetur adipiscing elit[/TD]
[TD]Lorem, elit[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]adipiscing elit[/TD]
[TD]Lorem ipsum dolor sit amet, consectetur adipiscing elit[/TD]
[TD]lorem, adipiscing elit, dolor sit ame, elit[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]dolor sit ame[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]elit[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Dear everyone,
+ I want to make a formula in excel to extract a list of keywords in a paragraph
+ If the results have multiple keywords, should be separated by a comma.


Anyone can help me to resolve? Many thanks for your support
 
I have a different UDF (user defined function) for you to try...
Code:
[table="width: 500"]
[tr]
	[td]Function GetKeywords(Paragraph As String, Keywords As Range) As String
  Dim X As Long, KW As Range, Parts() As String
  For Each KW In Keywords
    If InStr(1, Paragraph, KW, vbTextCompare) Then
      Parts = Split(" " & Paragraph & " ", KW, , vbTextCompare)
      If UBound(Parts) > 0 Then
        If Right(Parts(0), 1) Like "[!A-Za-z0-9]" And Left(Parts(0), 1) Like "[!A-Za-z0-9]" Then
          GetKeywords = GetKeywords & ", " & KW
        End If
      End If
    End If
  Next
  GetKeywords = Mid(GetKeywords, 3)
End Function[/td]
[/tr]
[/table]
The first argument is the text to search in and the second argument is the range containing the keywords to test for. So, for the example you posted in your original message (Message #1 ), put this formula in cell C2 and then copy it down as needed...

=GetKeywords(B2,A$2:A$5)

Note: Enter this formula normally
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I have a different UDF (user defined function) for you to try...
Code:
[table="width: 500"]
[tr]
	[td]Function GetKeywords(Paragraph As String, Keywords As Range) As String
  Dim X As Long, KW As Range, Parts() As String
  For Each KW In Keywords
    If InStr(1, Paragraph, KW, vbTextCompare) Then
      Parts = Split(" " & Paragraph & " ", KW, , vbTextCompare)
      If UBound(Parts) > 0 Then
        If Right(Parts(0), 1) Like "[!A-Za-z0-9]" And Left(Parts(0), 1) Like "[!A-Za-z0-9]" Then
          GetKeywords = GetKeywords & ", " & KW
        End If
      End If
    End If
  Next
  GetKeywords = Mid(GetKeywords, 3)
End Function[/td]
[/tr]
[/table]
The first argument is the text to search in and the second argument is the range containing the keywords to test for. So, for the example you posted in your original message (Message #1 ), put this formula in cell C2 and then copy it down as needed...

=GetKeywords(B2,A$2:A$5)

Note: Enter this formula normally
There is a minor error in my code... here is the corrected code for you to use (you would use it in the same way as described in Message #11 ).
Code:
[table="width: 500"]
[tr]
	[td]Function GetKeywords(Paragraph As String, Keywords As Range) As String
  Dim X As Long, KW As Range, Parts() As String
  Application.Volatile
  For Each KW In Keywords
    If InStr(1, Paragraph, KW, vbTextCompare) Then
      Parts = Split(" " & Paragraph & " ", KW, , vbTextCompare)
      If UBound(Parts) > 0 Then
        If Right(Parts(0), 1) Like "[!A-Za-z]" And Left(Parts(1), 1) Like "[!A-Za-z]" Then
          GetKeywords = GetKeywords & ", " & KW
        End If
      End If
    End If
  Next
  GetKeywords = Mid(GetKeywords, 3)
End Function[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
There is a minor error in my code... here is the corrected code for you to use (you would use it in the same way as described in Message #11 ).
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function GetKeywords(Paragraph As String, Keywords As Range) As String
  Dim X As Long, KW As Range, Parts() As String
  Application.Volatile
  For Each KW In Keywords
    If InStr(1, Paragraph, KW, vbTextCompare) Then
      Parts = Split(" " & Paragraph & " ", KW, , vbTextCompare)
      If UBound(Parts) > 0 Then
        If Right(Parts(0), 1) Like "[!A-Za-z]" And Left(Parts(1), 1) Like "[!A-Za-z]" Then
          GetKeywords = GetKeywords & ", " & KW
        End If
      End If
    End If
  Next
  GetKeywords = Mid(GetKeywords, 3)
End Function[/TD]
[/TR]
</tbody>[/TABLE]


hi Rick Rothstein i also tried with your code, but i saw one error

E.g.

Keyword: com
Paragraph: google.com
Expeted result: com

I didn't know why the system can find "com" in google.com
 
Upvote 0
hi Rick Rothstein i also tried with your code, but i saw one error

E.g.

Keyword: com
Paragraph: google.com
Expeted result: com

I didn't know why the system can find "com" in google.com
It would have helped if you had told us which error message you got (just saying there was an error does not help much). Also showing us how you called the function would also have helped. Given that, I'm just guessing at the error here... the second argument is a range, not a text string, so the keyword "com" needed to be in a cell and that cell (along with any other cells containing keywords) needed to be referenced in the function's second argument. Just so you know, when I tested the function, it found the word "com" as expected.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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