+ Reply to Thread
Results 1 to 13 of 13

Search for text within a string, lookup and then return item

  1. #1
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Search for text within a string, lookup and then return item

    Hi,

    I have a spreadsheet which is causing me a headache!

    I have two sheets, one of which contains film names and the other contains our tag structure for our website (which is a list of tags, their keywords and the primary parent channel they live under).

    What I am trying to do is search the film titles and if any of the words match either the tag name or keywords then return the relevant channel.

    Example:

    Sheet 1 - Films
    How To Apply Bridal Makeup
    How To Fight A Donkey
    How To Write Excel Formulae

    Sheet 2 - Tags
    Channel / Tag / Keywords
    Tech - Microsoft - windows vista xp word excel
    Tech - Computers - internet pc
    Tech - MP3 Players - iPod Zune


    So, for film 3 on Sheet 1 it would recognise the word Excel in the keyword list and return the channel Tech.

    Appreciate any help, if you need more info just let me know :-)

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    are the "keywords" on Sheet2 in separate columns or is it one long text string ?

    p.s. not sure I like the idea of film # 2

  3. #3
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    They are in separate columns (there were in a comma separated list but I text-to-columns'd them).

    EDIT: sorry, I was bored so made that up...we don't really have a film on Donkey fighting :-D
    Last edited by Raoul Duke; 09-30-2009 at 10:09 AM.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    If we assume then that your film titles are located

    Sheet1!A2:A4

    and that your keyword table is located

    Sheet2!A2:Z10

    with keywords being located in columns C onwards and Channel in Col A

    then... one possible yet hideously inefficient method to return Channel to Col B on Sheet 1 based on movie name might be:

    Please Login or Register  to view this content.
    The LOOKUP is used to handle those films that fail to return a Channel given no keywords can be located in the title.
    Last edited by DonkeyOte; 09-30-2009 at 11:03 AM. Reason: Typo - D2 refs should have been C2 per narrative (else ignoring 1st keyword)

  5. #5
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    Thanks - I'm having trouble getting it working though. I've created a spreadsheet to test just on the test data I made in my initial post but the formula doesn't seem to work - it returns blank cells.

    Could you break it down a little as to what the constituent parts do and how it functions as a whole?

    Thanks for your time

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    Here is a working example based on your data with a few extra checks thrown in for good measure (remember it is an Array so you must commit the formula holding CTRL + SHIFT + ENTER not just Enter)

    Could you break it down a little as to what the constituent parts do and how it functions as a whole?
    Yikes... that could take a while in truth... if we look at it like this:

    Please Login or Register  to view this content.
    the sections in red we will ignore as essentially this is used purely to cater for when no keywords can be found in the movie title.... so we're left with:

    Please Login or Register  to view this content.
    The INDEX reflects our results range - our channels... what comes after that is used to determine the row_number in which a keyword is first found in the title, so this:

    Please Login or Register  to view this content.
    Basically says if the keyword is not blank

    Please Login or Register  to view this content.
    and (by means of *) the keyword can be found within the movie title

    Please Login or Register  to view this content.
    then return the ROW number that contains the found keyword

    Please Login or Register  to view this content.
    else if you can't find it return the ROW above the last row in our table

    Please Login or Register  to view this content.
    This will generate an array of numerical values, one for each keyword in our keyword table... against which the MIN is applied

    Please Login or Register  to view this content.
    If none of the keywords have been found the MIN will return 11 as the entire array will be full of value 11 (not found output), however, if any keywords have been found they will return a lower number than 11... the MIN will thus pull the lowest number which if < 11 means a keyword was located.

    The INDEX uses the above output to establish which Channel to be returned

    Please Login or Register  to view this content.
    If no values were found and MIN is 11 then the INDEX will generate a #REF! error as there is no Row 11 in the range A1:A10 ... this is where the LOOKUP comes in as it handles those errors and returns a Null (this can be altered).

    If you post up your test file in which you're failing to get the desired results I will try and take a look at some point later today.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    Wow, this is ace! Thanks a lot. You are truly a champion.

    Much appreciated

  8. #8
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    Hi,

    I've now tested this on some real life data and currently it's getting 20% correct, compared to a human...not bad, but I'm looking to try and improve it.

    I was thinking that the one way in which it falls down is that it only searches on a single field (film title). As this is quite narrow it sometimes misses out an accurate keyword and selects something incorrect.

    What I'd like to do is have it look at different meta-data instead of the film title (the film's keywords) and see if that returns at a better rate.

    I've had a go at doing it but I can't figure out a way to make it look at a range instead of a single cell. Is this possible? It's kind of an array inside an array...

    Thanks!

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    Care to post an example of what you want to do ?

  10. #10
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    I've attached a version of what you sent to me yesterday - I was messing around with it but essentially I want to scan the film's keywords against the tag's keywords and return the channel of the tag keywords.

    Let me know if that doesn't make sense :-)
    Attached Files Attached Files

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    Not entirely clear... can you outline the purpose of each column ?

    As is stands...

    Col D appears to be a search with keywords matched against Film Keywords rather than Title (as implied)

    Col E appears to be a search of both tag & keywords against Film Title

    Col F is as before - ie a search of keywords against Film Title.

  12. #12
    Registered User
    Join Date
    02-14-2008
    Posts
    25

    Re: Search for text within a string, lookup and then return item

    Sorry - the attachment was basically my attempts at improving the equation, so it's probably gibberish.

    In Sheet1 D2, what I was trying to do is, where it references $B$2 is to have it look at a range (the film's keywords), e.g. B2:C2 and try to match one of them to the Sheet2 tags.

  13. #13
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search for text within a string, lookup and then return item

    You can concatenate B2 & C2 to create one string into which the keywords search (ie concatenation of film keyword becomes akin to film title)

    Please Login or Register  to view this content.
    is that what you meant ?

    there may be better methods now you're essentially splitting the film title in effect into separate cells with one word in each ... I would need to have a think - if that is indeed the intention ?

    If this is along the right lines I would suggest perhaps another sample file with more films etc which reflect different scenarios such that we can conduct some tougher testing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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