+ Reply to Thread
Results 1 to 3 of 3

Automate count of matched keywords by search

  1. #1
    Registered User
    Join Date
    01-17-2015
    Location
    USA
    MS-Off Ver
    2007
    Posts
    2

    Automate count of matched keywords by search

    Thank you for taking the challenge to help!!
    I need a Macro to automate search and check function in Microsoft Excel. In the following example, the Macro should search each cell in column-A (STAFF MEMBERS) with keywords from B1 (DARK HAIR), C1, D1 ... etc. For a search match (between keywords and STAFF MEMBER column), enter "1", otherwise enter "0" in the corresponding cell of the row. The challenges are two: 1) negation statement -- "No dark hair" is NOT a match to keywords "DARK HAIR" nor is "Daily jog is not ... " to "DAILY JOG"; other negation statements may be "cannot (jog daily)", "negative for (DARK HAIR)", " ... is negative" and "free of (SUN BURN)". 2) semantic unit. # is used as a marker for each semantic unit. The search has to treat one cell as multiple units.

    A B C D E F
    1 STAFF MEMBERS DARK HAIR RED SOX FAN DAILY JOG SUN BURN ...
    2 Jack: #Dark hair. #No sun burn. #Red Sox fan. 1 1 0 0 ...
    3 Jill: #No dark hair. #Red socks fan. #free of sun burn. 0 1 0 0 ...
    4 Sam: #Daily jog is not reported. #dark hair. 1 0 0 0 ...
    5 Joe: #Negative for sun burn. #cannot daily jog. #Dark hair. 1 0 0 0 ...
    5 ... ... ... ... ... ... ...

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Automate count of matched keywords by search

    Try putting this in B2 and dragging right and down.

    =COUNTIF($A2, "*#"&B$1&".*")

    (You have to decide whether it is spelt "socks" or "sox" for this to work. )
    Last edited by mikerickson; 01-17-2015 at 07:26 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    01-17-2015
    Location
    USA
    MS-Off Ver
    2007
    Posts
    2

    Re: Automate count of matched keywords by search

    Thank you (Mikerichson) very much. Your approach (with formula) is ingenious. It deals with negation statement by treating keywords with any preceding and trailing letter(s) as unmatched. Thus, "#Sun burn is negative" is treated the same as "Sun burn is mild" or "Severe sun burn" despite the opposite meanings. This approach works well with highly structured data as those given in the example. But it is unlikely to work for data with slight syntax variation (i.e., "#No sun burn." and "#Severe sun burn." or "#Sun burn is present."). Intuitively, I think that a Macro with multiple lines of code is probably the only way to deal with such unstructured negation statements since, in addition to the various forms of negation, the length of statement can be another variable (e.g. "#No dark hair, red sox fan or sun burn is present."). But I really like the formula approach and wonder whether that would work when syntax variation of negation statement is limited to a small number: No ..., Negative ..., negative for..., ... not ..., without ..., with no ..., free of ... . Hope to get your expert opinion on the issue. Gratefully yours.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Search for keywords and copy rows containing keywords to new sheet
    By lenorsk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-15-2013, 06:54 AM
  2. To search Keywords
    By narendrabr in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-16-2013, 07:03 AM
  3. [SOLVED] Search By Keywords
    By Auni in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-19-2013, 07:00 AM
  4. search multiple columns and count number of rows the keywords appear
    By vincegc8 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-22-2013, 02:01 PM
  5. Search based on keywords in pop up box
    By forumsk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-10-2009, 05:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1