+ Reply to Thread
Results 1 to 5 of 5

Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Southfield, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    63

    Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

    Hi,

    I have a list of 500 terms in column A. (The sheet is called "TERMS")

    On a separate spreadsheet in the same workbook, I have a list of single words. The list (let's say it's in column B) has 3000 rows.

    (This sheet for simplicity is named "SUBSTRINGS)



    I need a formula let's say column C on the "TERMS" sheet that will check EACH of the 500 cells in column TERMS" to determine if ANY of the 3000 words in the worksheet "SUBSTRING" is somewhere in the string.


    So, Col A of Worksheet TERMS contains:

    A1 = John sells lemonade for $1 per glass
    A2 = Carla loves her dogs
    A3 = Superman leaps tall buildings in a single bound


    Let's Col B of worksheet SUBSTRINGS contains:

    Superman
    dogs
    computers
    cats
    Batman
    John
    leaps
    likes


    I need a formula or formulas that:

    1) Returns whether or not a word from SUBSTRING is in the particular cell of TERMS
    and
    2) Returns WHERE the substring begins.

    I would like to do this using a formula (or 2 if necessary) but if a Macro is the way to go due to the number of calculations, I would of course be open to using that as well.

    Any help would be greatly appreciated!

    Thanks!

    R.J.

  2. #2
    Registered User
    Join Date
    04-05-2012
    Location
    Southfield, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

    I actually figured this one out.

    I listed it below in case anyone else ever needs a formula like this:

    "=INDEX('SUBSTRINGS'!$A$1:$A$3000,MATCH(TRUE,ISNUMBER(SEARCH('SUBSTRINGS'!$A$1:$A$3000,'TERMS'!$B3)),0))"

    R.J.

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

    You may also use this formula to lookup and return key-words. Also, you may get better results if sort your lookup list in ascending order.

    =IF(ROWS(A$2:A2)>COUNTA(A:A)-1,"",LOOKUP(10^308,SEARCH($C$2:$C$9,A2),$C$2:$C$9))

    Row\Col
    A
    B
    C
    1
    Original string Returned values Key-words
    2
    John sells lemonade for $1 per glass John Batman
    3
    Carla loves her dogs dog cat
    4
    Superman leaps tall buildings in a single bound Superman computers
    5
    dog
    6
    John
    7
    leap
    8
    like
    9
    Superman
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Registered User
    Join Date
    04-05-2012
    Location
    Southfield, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

    Hi AllKey,

    I actually like this formula a lot. It looks much cleaner.

    I'm having a little trouble following the logic of it however.

    Would it be asking too much if you could give a quick explanation of what this formula is doing exactly? I'd love to understand it better.

    Thanks!

    R.J.

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula to See if a Range of Substrings is in a Particular cell and Where it begins...

    Quote Originally Posted by rjw524 View Post
    Hi AllKey,

    I actually like this formula a lot. It looks much cleaner.

    I'm having a little trouble following the logic of it however.

    Would it be asking too much if you could give a quick explanation of what this formula is doing exactly? I'd love to understand it better.

    Thanks!

    R.J.
    The first part =IF(ROWS(A$2:A2)>COUNTA(A:A)-1,"" is there to stop formula to prevent error when there is no more rows of data in column A. Since you still using Excel 2003, as it shows in your profile, there other option would be to use "IF(ISERROR(your formula,"", your formula)" but that would also make the formula much longer. There are better options for those who use Excel 2007 and higher.

    The second part is LOOKUP and SEARCH combination:

    The SEARCH($C$2:$C$9,A2),$C$2:$C$9)

    Here formula will look in each cell starting with A2, to find key-words located in column C and if any of the words found it will return the first matched word from the same column C. But the key to all this is the LOOKUP function: LOOKUP(10^308 and 10^308

    10^308 is an enormously large number that can be entered in Excel and most likely doesn't exist withing the lookup_vector. Since the LOOKUP function typically works on a sorted (ascending order) range it will go for the last row assuming that this where the largest value exists. However, when used with SEARCH or FIND functions, the only number it will find is the one returned by search function.

+ 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. Resultant cell to be blank, not zero, until range begins population
    By craigl in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-07-2015, 03:27 PM
  2. [SOLVED] if cell BEGINS WITH abc, then return 123, or if cell BEGINS WITH def, then 456, ...
    By Marijke in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-29-2013, 11:20 AM
  3. Excel formula/VBA for IF cell A= 'xx' but cell B begins with 'yyyy'
    By whizzergo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-03-2013, 08:48 AM
  4. [SOLVED] Count Substrings in a range
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-14-2012, 05:21 PM
  5. Replies: 3
    Last Post: 03-04-2011, 02:25 PM

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