+ Reply to Thread
Results 1 to 16 of 16

Using Search, Index, Lookups, Etc.

  1. #1
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Using Search, Index, Lookups, Etc.

    I think I'm making this way harder than it probably is. I need to search for certain text within a field. If it is found I want to apply a value when found.

    For example.

    Column A Is the column I'm searching
    A1 - 123 Jason
    A2 - New York
    A3 - Atlantic Ocean

    Column B Is the column I'm comparing against or searching for
    B1 - Jason
    B2 - York

    Column C
    C1 - Football (If Jason was found in the range A1:A3 the output would be Football)
    C2 - Soccer (If York was found in the range A1:A3 the output would be Soccer)

    As you can tell I want to search the entire column A. I also want to search using the entire (index/range, etc.) of Column B. It would not have to be case sensitive. Thanks for your help!

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Using Search, Index, Lookups, Etc.

    I think the formula you want for C1 is =IF(SUMPRODUCT(--(NOT(ISERROR(SEARCH(B1,A1:A3))))),"Football") changed to B2 and "Soccer" for C2.

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

    Re: Using Search, Index, Lookups, Etc.

    Try,

    =IF(COUNTIF($A$1:$A$3,"*"&B1&"*"),C1,"")

    copied down
    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.

  4. #4
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    Andrew -- that looks similiar to something in another post. My only problem.. It doesn't seem to pass the fact that if it finds a match using B22... (on A15) for example, that the output is C22.

    NBVC -- this seems closer...same sort of problem though. If I pulled this formula down.. the last two variables would be B2 ---C2.... B12 ---C12...etc. I have to pass the corresponding value in Column C when there is a matching using the key from Column 2.


    The data I'm using this on is really complex. For example, the field sizes can be in the hundreds.. and I would have to find a Code, Number, Name etc. I am gonna have "rules" in the thousands once I make them up based on the data.

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

    Re: Using Search, Index, Lookups, Etc.

    So are you looking in column A, say at A1, and looking for a match in the table B1:C2 and as you copy down you are looking at A2 for the a match in same table, etc.?

    Something like:

    =LOOKUP(9.99999,Search($B$1:$B$2,A1),$C$1:$C$2)

    This looks at column A as you copy down for matches in column B and returns column C results at same location.

  6. #6
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    Correct! Trying to decipher your formula. What's the purpose of the 9.9999? Also can I just use a column instead of an absolute range? I'm assuming the absolute range will help with the speed.

    This last solution seems really close.

    There are still some kinks to work out in the data analysis side but here is the beast I'm working with. One of major problems we have until the rules are more formalized is we're using two fields to "search". I'm just trying to get one to work for now. It'll probably end up being a two step processing or incorporate an IF THEN with one field prioritizing the other. Another problem is some of the criteria fields are blanks so that is passing a match.

    Column X is the column I'm searching.
    Column Y is where the formula is.

    ID TI is the rules worksheet. Column B and D are applicable in this worksheet.
    The output should match Column Z.
    Attached Files Attached Files

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

    Re: Using Search, Index, Lookups, Etc.

    How do you get Massimo - TI at Z4 for the entry made in X4.

    To me nothing in X4 matches the sole entry for Massimo - TI in the other sheet.

  8. #8
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    Good point.

    I'm not the one making the rules. The COFIROASTERS rule for MASSIMO might have came from more of the data. I had to reduce the file for it to be under 1MB. He might have just outlooked it early on. These were made really briefly Friday before we left to give me something to start with this morning.

    I don't get the current formula to pick up NIVERSAL FURNITURE in Y11 though.

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

    Re: Using Search, Index, Lookups, Etc.

    Okay let's try this:

    First, let's create a dynamic named range, so the number of rows occuppied is the range limit...and you can add/subtract rows as necessary.

    so while in ID TI sheet go to Formulas|Define Name and then enter a name for your range, e.g. MyRange then enter a formula in the Refers to field:

    Please Login or Register  to view this content.
    click Ok

    That range depends on column D... so it will go to the last row in column D containing text.

    Then in Y2 of the other sheet enter:

    Please Login or Register  to view this content.
    You have to confirm this formula with CTRL+SHIFT+ENTER not just ENTER and then copy down.

    This formula will ignore the blank entries in column B of the ID TI sheet.

  10. #10
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    This seems to work great considering only half the rules are probably even in the ID TI table.

    I still need to look over some of the logic to fully understand it. Mostly the lookup value part and the 255 part of the INDEX NAME. I'll add to this post if I have any further issues as I move along.

    Thanks for all your help.

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

    Re: Using Search, Index, Lookups, Etc.

    The REPT("z",255) part in MATCH(REPT("z",255),'ID TI'!$D:$D) creates a string of 255 z's. In the MATCH function, it is looking for this obscure string in column D.... since MATCH() function here doesn't include the last option argument of 0 to look for an exact match, it then tries to find the last time a match that is smaller than or equal to the string of z's occurs. Not finding it, it references the last string in the column (which is the last time a string is smaller than a string of z's)... Match returns the position within column D.. and that is then Indexed against 'ID TI'!$F:$F to give the last cell to include in the named range.

    LOOKUP(9.9999999E+307.. works much the same way, but since we are going to deal with numbers instead of strings, then Rept("z",255) won't work... instead we "look for" the largest number Excel recognizes...

    The SEARCH() function looks for matches and returns a position number, if found, or error... the LOOKUP simply looks for the last time a position number is smaller than or equal to that big number.. and so, the last time the string to search is found, it uses that result to get the value at the same position in column D.

    Hope it helps a bit.

  12. #12
    Registered User
    Join Date
    09-15-2011
    Location
    San Francisco, California
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Using Search, Index, Lookups, Etc.

    Hello,

    I'd appreciate some help. In my spreadsheet, Column L consists of cells containing a variety of phrases, I need column M to show a number according to the phrase in the corresponding L cell. Column M looks like this

    Column M
    TRF
    OVERTIME
    REGULAR
    NIGHT SHIFT
    PREMIUM PAY

    There are thousands of entries so the phrases are repeated and there are a few other phrases. I need to insert a formula that says, if M2 = overtime, 5, if M2=night shift, 4 and so on, and the last part of the formula needs to be "if not any of the mentioned phrases",""

    Please help me!

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

    Re: Using Search, Index, Lookups, Etc.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  14. #14
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    I noticed the formula seems to split the text between spaces when searching. Where if you are searching WALMART, it wouldn't pick up TO:WALMART.

    I assume this is because its assigning a numerical value to each string delimited by the spaces. Is there any direction you can point me in or help me with that might allow me to search within strings where I would find the match above?

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

    Re: Using Search, Index, Lookups, Etc.

    I had added that feature specifically to avoid "false" positives., like if you want to look for the word "son", you wouldn't necessarily want it to pick up Johnson...

    To remove the feature change formula to:

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    10-27-2010
    Location
    NC, United States
    MS-Off Ver
    2007
    Posts
    32

    Re: Using Search, Index, Lookups, Etc.

    I guess that goes back to your quote, "Where there is a will there are many ways"

    We also contemplated maybe looping a find & replace and putting the necessary space or delimiter around key pieces before doing the lookup. Only time will tell what ends up being better. Thanks again.

+ 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