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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
B2 and B3 are the same. Wouldn't you expect the same result in C2 and C3?
 
Upvote 0
lcqb0f
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]keyword[/TD]
[TD]Paragraph[/TD]
[TD]Expected Result[/TD]
[/TR]
[TR]
[TD][TABLE="width: 105"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Lorem[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 421"]
<tbody>[TR]
[TD="class: xl65, width: 421"]Lorem ipsum dolor sit amet, consectetur adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 242"]
<tbody>[TR]
[TD="class: xl65, width: 242"]Lorem, amet, adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 105"]
<tbody>[TR]
[TD]Amet[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 421"]
<tbody>[TR]
[TD="class: xl65, width: 421"]Vivamus iaculis id libero ut pulvinar, consectetur adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 242"]
<tbody>[TR]
[TD="class: xl65, width: 242"]Iaculis, Adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 105"]
<tbody>[TR]
[TD]Iaculis[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 421"]
<tbody>[TR]
[TD="class: xl65, width: 421"]Aenean quis cursus lectus, dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 242"]
<tbody>[TR]
[TD="class: xl65, width: 242"]Dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 105"]
<tbody>[TR]
[TD]adipiscing elit[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dolor sit ame[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Hi Mr shg, just like this, could you support me? thanks you so much
 
Upvote 0
[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
keyword
[/td][td="bgcolor:#F3F3F3"]
paragraph
[/td][td="bgcolor:#F3F3F3"]
Expected Result
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]Lorem[/td][td]Lorem ipsum dolor sit amet, consectetur adipiscing elit[/td][td="bgcolor:#CCFFCC"]Lorem, Amet, adipiscing elit, dolor sit ame[/td][td="bgcolor:#CCFFCC"]C2: {=CatIf(ISNUMBER(SEARCH($A$2:$A$6, B2)), $A$2:$A$6, ", ")}[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]Amet[/td][td]Vivamus iaculis id libero ut pulvinar, consectetur adipiscing elit[/td][td="bgcolor:#CCFFCC"]Iaculis, adipiscing elit[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]Iaculis[/td][td]Aenean quis cursus lectus, dolor sit ame[/td][td="bgcolor:#CCFFCC"]dolor sit ame[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]adipiscing elit[/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]dolor sit ame[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Code:
Function CatIf(avbIf As Variant, _
               rInp As Range, _
               Optional sSep As String = ",", _
               Optional bCatEmpty As Boolean = False) As String
  ' shg 2007
  ' UDF only

  ' Catenates the elements of rInp separated by sSep where the corresponding
  ' element of avbIf is True. Empty cells ignored unless bCatEmpty is True.

  Dim iRow          As Long
  Dim iCol          As Long
  Dim i             As Long

  If TypeOf avbIf Is Range Then avbIf = avbIf.Value
  If Not IsArray(avbIf) Then avbIf = Array(False, avbIf)
  
  On Error Resume Next
  i = UBound(avbIf, 2)

  If Err.Number Then
    ' avbIf is 1D
    For iRow = 1 To rInp.Rows.Count
      For iCol = 1 To rInp.Columns.Count
        i = i + 1
        If avbIf(i) Then
          If bCatEmpty Or Not IsEmpty(rInp(iRow, iCol).Value2) Then
            CatIf = CatIf & rInp(iRow, iCol).Value2 & sSep
          End If
        End If
      Next iCol
    Next iRow
  Else
    ' it's 2D
    For iRow = 1 To rInp.Rows.Count
      For iCol = 1 To rInp.Columns.Count
        If avbIf(iRow, iCol) Then
          If bCatEmpty Or Not IsEmpty(rInp(iRow, iCol).Value2) Then
            CatIf = CatIf & rInp(iRow, iCol).Value2 & sSep
          End If
        End If
      Next iCol
    Next iRow
  End If

  If Len(CatIf) Then CatIf = Left(CatIf, Len(CatIf) - Len(sSep))
End Function
 
Upvote 0
hi MR SHG, I run follow you, but the result as below. This is my step
1. Alt F11 - > insert -> module - > paste code
2. Put =CatIf(ISNUMBER(SEARCH($A$2:$A$6,B2)),$A$2:$A$6,", ") to C2

Could you let me know what i wrong? Thanks you

[TABLE="class: cms_table_grid, width: 500"]
<tbody>[TR]
[/TR]
[TR]
[TD]keyword[/TD]
[TD]Paragraph[/TD]
[TD]Expected Result[/TD]
[/TR]
[TR]
[TD][TABLE="class: cms_table, width: 105"]
<tbody>[TR]
[TD]Lorem[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 421"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 421"]Lorem ipsum dolor sit amet, consectetur adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 242"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 242"][TABLE="width: 402"]
<tbody>[TR]
[TD="class: xl65, width: 402"]Lorem, Amet, Iaculis, adipiscing elit, dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[/TR]
[TR]
[TD][TABLE="class: cms_table, width: 105"]
<tbody>[TR]
[TD]Amet[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 421"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 421"]Vivamus iaculis id libero ut pulvinar, consectetur adipiscing elit[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 242"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 242"][TABLE="width: 402"]
<tbody>[TR]
[TD="class: xl65, width: 402"]Amet, Iaculis, adipiscing elit, dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[/TR]
[TR]
[TD][TABLE="class: cms_table, width: 105"]
<tbody>[TR]
[TD]Iaculis[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 421"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 421"]Aenean quis cursus lectus, dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][TABLE="class: cms_table, width: 242"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 242"][TABLE="width: 402"]
<tbody>[TR]
[TD="class: xl65, width: 402"]Amet, Iaculis, adipiscing elit, dolor sit ame[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[/TR]
[TR]
[TD][TABLE="class: cms_table, width: 105"]
<tbody>[TR]
[TD]adipiscing elit[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dolor sit ame[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
The formula needs to be confirmed with Ctrl+Shift+Enter rather than just Enter.
 
Upvote 0
Dear mr SHG
I have more question. How to find in case text must exactly?
E.g.


Lorem ipsum dolor sit amet, consectetur adipiscing elit


Keyword: it
You can see the paragraph didn't "it"


But Expected result still show it. maybe it get from "sit"


How to resolve it MR SHG ? Thanks you
 
Upvote 0
Add a space before and after each entry in col A and change the formula to

=CatIf(ISNUMBER(SEARCH($A$2:$A$7, " " & B2 & " ")), $A$2:$A$7, ",")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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