identify specific keywords (plural) in a column of text

dominicp

New Member
Joined
Nov 3, 2009
Messages
15
So i'm try to automate a process that I currently do using filters.

Here is the problem:

I have a list of text in a column (usually 700 or so entries).

I need to remove any entries that contain 1 of 42 keywords.

So I need a fast way to search each cell for each one of the 42 key words and flag the cell for deletion if contains anyone of the 42.

example
A
1 This field has keyword1
2 This field has keyword2
3 This field doesn't have any of the 42 keywords


somewhere else I would have a list of keywords in a column.

Thanks for the help.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi and welcome to the board!!!
Is the Keyword the ONLY thing in the cell, or can it contain other text??
lenze
 
Upvote 0
dominicp,

Sample data on Sheet1 before the macro:


Excel Workbook
AB
1This field has keyword1
2This field has keyword2
3This field doesn't have any of the 42 keywords
4
Sheet1



And, sheet "Keywords":


Excel Workbook
A
1keyword1
2keyword2
3keyword3
4
Keywords



Sheet1 after the macro:


Excel Workbook
AB
1This field has keyword1Delete
2This field has keyword2Delete
3This field doesn't have any of the 42 keywords
4
Sheet1




Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel


Code:
Option Explicit
Option Base 1
Sub CKKeywords()
Dim c As Range, a As Long, b As Long
Dim MyKeys As Variant
Application.ScreenUpdating = False
MyKeys = Sheets("Keywords").Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
With Sheets("Sheet1")
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  For a = LBound(MyKeys) To UBound(MyKeys)
    b = 0
    On Error Resume Next
    b = WorksheetFunction.Find(MyKeys(a, 1), c, 1)
    On Error GoTo 0
    If b > 0 Then
      c.Offset(, 1) = "Delete"
      Exit For
    End If
  Next a
Next c
End With
Application.ScreenUpdating = True
End Sub


Then run the "CKKeywords" macro.
 
Upvote 0
Hi lenze,

glad to be on the board..

The cells do contain more than just the keywords.

The entries are anywhere from 1 word to 5 words and can also contain punctuation.

hope that helps.
Thanks,
Dominic
 
Upvote 0
Here's a made-to-order solution:
Excel Workbook
ABCD
1list of identifierstext string to searchsearch result
2taisteve knows what's beststeve
3ryanbetter ask lori for permissionlori
4stevego to marty for excel helpmarty
5martywhy does tai work so hard for this company?tai
6johnwhat exactly does ryan DO in ppt all day?ryan
7joeprocess time + joe = process time / 2joe
8lorijohn brought cookiesjohn
Sheet1
Excel 2003
Cell Formulas
RangeFormula
D2=IF(ISERROR(LOOKUP(9.9999999E+307,SEARCH(search_list,C2),search_list)),"",LOOKUP(9.9999999E+307,SEARCH(search_list,C2),search_list))
Excel Workbook
NameRefers To
search_list=OFFSET(Sheet1!$A$1,,,COUNTA(Sheet1!$A:$A),1)
Workbook Defined Names


Copy the formula down; you can use a named range, or substitute the range name in the formula with an absolute reference. Note that if there are multiple matches, the formula will return the *last* match in your search list - so you can sort your search list accordingly.
 
Upvote 0
Dominic:
It appears you have the best of both worlds from Hiker and Tai. Your choice!!
Formula or Macro?

lenze
 
Upvote 0
Hiker...

tried your code but resulted in all fields being marked deleted...

any thoughts on what i could be doing wrong..

Sample of text i'm searching:
<table style="border-collapse: collapse; width: 198pt;" border="0" cellpadding="0" cellspacing="0" width="264"><col style="width: 198pt;" width="264"> <tbody><tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt; width: 198pt;" height="20" width="264">Garrison Opportunity Fund LLC</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" height="20">Earth Wind & Fire Fund Ltd.</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" height="20">FX Bridge Technologies Corp</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" height="20">FX Bridge Technologies Corp</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl64" style="height: 15pt;" height="20">CHATA BIOSYSTEMS INC</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl64" style="height: 15pt;" height="20">Thornton Holding Company, Inc.</td> </tr> </tbody></table>
These start in cell A1 on Sheet1

Sample of keywords

<table style="border-collapse: collapse; width: 140pt;" border="0" cellpadding="0" cellspacing="0" width="186"><col style="width: 140pt;" width="186"> <tbody><tr style="height: 15pt;" height="20"> <td style="height: 15pt; width: 140pt;" height="20" width="186">Manager</td> </tr> <tr style="height: 15pt;" height="20"> <td style="height: 15pt;" height="20">Holding</td> </tr> <tr style="height: 15pt;" height="20"> <td style="height: 15pt;" height="20">Fund</td> </tr> <tr style="height: 15pt;" height="20"> <td style="height: 15pt;" height="20">LLP</td> </tr> <tr style="height: 15pt;" height="20"> <td style="height: 15pt;" height="20">LP</td> </tr> <tr style="height: 15pt;" height="20"> <td style="height: 15pt;" height="20">L.P.</td> </tr> </tbody></table>
These start on cell A1 on sheet "Keywords"
 
Upvote 0
Maybe...

B1, copied down:

=IF(ISNUMBER(LOOKUP(9.99999999999999E+307,SEARCH(" "&Keywords!$A$1:$A$6&" "," "&A1&" "))),"Y","")

or

=ISNUMBER(LOOKUP(9.99999999999999E+307,SEARCH(" "&Keywords!$A$1:$A$6&" "," "&A1&" ")))+0
 
Upvote 0
dominicp,

Sample data before the macro:


Excel Workbook
AB
1Garrison Opportunity Fund LLC
2Earth Wind & Fire Fund Ltd.
3FX Bridge Technologies Corp
4FX Bridge Technologies Corp
5CHATA BIOSYSTEMS INC
6Thornton Holding Company, Inc.
7
Sheet1



Excel Workbook
A
1Manager
2Holding
3Fund
4LLP
5LP
6L.P.
7
Keywords




After the macro:


Excel Workbook
AB
1Garrison Opportunity Fund LLCDelete
2Earth Wind & Fire Fund Ltd.Delete
3FX Bridge Technologies Corp
4FX Bridge Technologies Corp
5CHATA BIOSYSTEMS INC
6Thornton Holding Company, Inc.Delete
7
Sheet1





I have modified the macro to account for the fact that all the trailing spaces in each data cell in your Sheet1 and sheet Keywords:


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel


Code:
Option Explicit
Option Base 1
Sub CKKeywords()
Dim c As Range, a As Long, b As Long
Dim MyKeys As Variant
Application.ScreenUpdating = False
MyKeys = Sheets("Keywords").Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
With Sheets("Sheet1")
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  For a = LBound(MyKeys) To UBound(MyKeys)
    b = 0
    On Error Resume Next
    b = WorksheetFunction.Find(Trim(MyKeys(a, 1)), c, 1)
    On Error GoTo 0
    If b > 0 Then
      c.Offset(, 1) = "Delete"
      Exit For
    End If
  Next a
Next c
End With
Application.ScreenUpdating = True
End Sub



Then run the "CKKeywords" macro.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

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