+ Reply to Thread
Results 1 to 9 of 9

LOOKUP function with SEARCH and INDIRECT

  1. #1
    Registered User
    Join Date
    01-30-2013
    Location
    South Carolina
    MS-Off Ver
    2010
    Posts
    10

    Cool LOOKUP function with SEARCH and INDIRECT

    Hello,

    I'm stuck on a part of my spreadsheet

    I have a worksheet that is pulling formulas based on text that is pasted in. I found a formula online that has been very helpful (but confusing), allowing me to look up a column of text items within one cell and return a result based on the item found.

    =LOOKUP(9.99999999999999E+307,SEARCH(" "&Lists!$A$2:$A$1000&" "," "&H2&" "),Lists!$B$2:$B$1000)

    This is searching for any text listed in a cell between A2:A1000 inside of cell H2 and returning the corresponding result from B2:B1000. I do not know why the " " are necessary at the beginning and end of the SEARCH function, but the whole formula doesn't work if they aren't there.

    I need this formula to reference the H column and the row the formula is on, so I thought I could use an indirect function....

    =LOOKUP(9.99999999999999E+307,SEARCH(" "&Lists!$A$2:$A$1000&" "," "&INDIRECT("H"&ROW())&" "),Lists!$B$2:$B$1000)

    However, this returns #N/A

    Anybody know why INDIRECT would break it?



    Thank you!
    Last edited by bubbacheese; 03-13-2013 at 04:01 PM.

  2. #2
    Forum Contributor
    Join Date
    09-27-2012
    Location
    Florida
    MS-Off Ver
    Excel XP to 2013
    Posts
    342

    Re: LOOKUP function with SEARCH and INDIRECT

    Try removing the last ) in this section INDIRECT("H"&ROW())&" ",
    Tom S.
    ↙ If you find my reply helpful click on the * down there on the left. Yeah that's it, right there, down on the left
    If your question is resolved, mark it SOLVED using the thread tools.

  3. #3
    Registered User
    Join Date
    01-30-2013
    Location
    South Carolina
    MS-Off Ver
    2010
    Posts
    10

    Re: LOOKUP function with SEARCH and INDIRECT

    Thank you for the quick response!

    OK, so it would be:

    =LOOKUP(9.99999999999999E+307,SEARCH(" "&Lists!$A$2:$A$1000&" "," "&INDIRECT("H"&ROW())&" ",Lists!$B$2:$B$1000)

    I get an error that the formula is missing a parenthesis if I remove it. It's the closing parenthesis for the SEARCH function.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: LOOKUP function with SEARCH and INDIRECT

    Try:

    =LOOKUP(9.99999999999999E+307,SEARCH(" "&Lists!$A$2:$A$10&" "," "&INDIRECT(INDIRECT(TRANSPOSE(ADDRESS(ROW(),8))))&" "),Lists!$B$2:$B$10)

    The ADDRESS(ROW(),8) translates to "H"&ROW()

    The TRANSPOSE converts the array range returned by the SEARCH() function to a single value...

    The nested INDIRECT is needed because the inner INDIRECT returns the value (cell reference) that is in H&ROW(), then the outer one returns what is in that indirect reference.
    Last edited by NBVC; 03-13-2013 at 03:18 PM.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: LOOKUP function with SEARCH and INDIRECT

    Try it like this:

    =LOOKUP(32768,SEARCH(" "&Lists!$A$2:$A$1000&" "," "&T(INDIRECT("H"&ROW()))&" "),Lists!$B$2:$B$1000)

    The concatenated spaces make sure that you don't get "false positives".

    For example, if you search for "try" it won't match with "trying".

    " "try" " will not be found in " "trying" "
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Registered User
    Join Date
    01-30-2013
    Location
    South Carolina
    MS-Off Ver
    2010
    Posts
    10

    Re: LOOKUP function with SEARCH and INDIRECT

    Thank you very much NBVC!

    I tried INDIRECT(INDIRECT(TRANSPOSE(ADDRESS(ROW(),8)))) but that still resulted in a #N/A

    However, INDIRECT(TRANSPOSE(ADDRESS(ROW(),8))) works perfectly.

    I have a lot to learn and I appreciate everyone's help with this.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: LOOKUP function with SEARCH and INDIRECT

    I guess I had assumed you have a cell reference in column H that you needed to redirect too....

    but glad it worked

  8. #8
    Registered User
    Join Date
    01-30-2013
    Location
    South Carolina
    MS-Off Ver
    2010
    Posts
    10

    Re: LOOKUP function with SEARCH and INDIRECT

    Quote Originally Posted by Tony Valko View Post
    Try it like this:

    =LOOKUP(32768,SEARCH(" "&Lists!$A$2:$A$1000&" "," "&T(INDIRECT("H"&ROW()))&" "),Lists!$B$2:$B$1000)

    The concatenated spaces make sure that you don't get "false positives".

    For example, if you search for "try" it won't match with "trying".

    " "try" " will not be found in " "trying" "
    This works too, awesome. One question, why the "T" before the INDIRECT ?

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: LOOKUP function with SEARCH and INDIRECT

    Quote Originally Posted by bubbacheese View Post
    This works too, awesome.
    Good deal!

    One question, why the "T" before the INDIRECT ?
    No one really knows for sure WHY INDIRECT("H"&ROW()) throws an error. This happens when an array is evaluated in the INDIRECT function. The ROW() function returns an array, even if it's a single element.

    I've seen some explanations that say the reference gets "dereferenced".

    Right!

    However, I do know that including the T(...) function when the data is TEXT fixes the problem.

+ 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