+ Reply to Thread
Results 1 to 10 of 10

difficult lookup problem

  1. #1
    Forum Contributor
    Join Date
    12-12-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    448

    difficult lookup problem

    I've been spending an eternity trying to figure this out with no luck. I need a look up for the following example sheet that I've attached. I need to do a lookup on the second column but the values are not unique. The first column has unique values (and segments in column 2 correspond to these values) but they are only written once and I do not want to copy them. The other issue is that the report is constantly changing rows so I cannot just do a lookup on a segment. PLEASE HELP!!!!

    For purposes of this example, let's say I want to get the value in C7 and use the value in column B (which isn't unique) as a lookup. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: difficult lookup problem

    Can do this one with a user defined function

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In a suitable cell, enter = =LookupSpecial(A:A,"Department 2",B:B,"Bob",C:C) for example. The three ranges need to be entire columns.

    Remember to save the workbook as a macro enabled workbook .xlsm
    Martin

  3. #3
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: difficult lookup problem

    With the goal of finding the name to the left of an entry in G1 (5 in your example):

    =INDEX(B$1:B$12,MATCH(G1,C$1:C$12,0))

  4. #4
    Forum Contributor
    Join Date
    12-12-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    448

    Re: difficult lookup problem

    This might work but it's giving me the "Name" error. I inserted a module in VBA personal folder but it's not working

  5. #5
    Forum Contributor
    Join Date
    12-12-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    448

    Re: difficult lookup problem

    bentleybob, what you wrote doesn't make sense (to me). I'm looking for the value in column C. Why do you say "5 in my example" referring to G1? Confused....If I put a 5 in G1 it gives me the value of Bob, but that's not what I need. I need the lookup to use the Bob (specific to a department) to get the value in Column C

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: difficult lookup problem

    Please see the attachment.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    12-12-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    448

    Re: difficult lookup problem

    Nice. Not sure what I was doing wrong. Now....Is there a way that I can refer to cells rather than hard coding "Department" and "Name"? In the tab I'm importing INTO I have a column with the lookup. I'm thinking about just writing Department hard coded but for the name I would like to just refer to the column/row. Is this possible? Thanks a lot.

  8. #8
    Forum Contributor
    Join Date
    12-12-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    448

    Re: difficult lookup problem

    Also, does this work if I refer to a different tab? In the example I gave you everything was in one tab, but for the real thing, I will be using the lookup in one tab and pulling from the other tab.

  9. #9
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: difficult lookup problem

    An example of use across tabs is attached. The example also shows the use of cell references as opposed to literal values.
    Attached Files Attached Files

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: difficult lookup problem

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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