+ Reply to Thread
Results 1 to 14 of 14

Multiple lookup with non-adjacent columns

  1. #1
    Registered User
    Join Date
    06-18-2014
    Location
    USA
    MS-Off Ver
    2007-2008
    Posts
    9

    Multiple lookup with non-adjacent columns

    Hi,

    I'd like to be able to search a column (F) for 5 possible values, then return the values from column R in any row where one of those 5 values appeared in column F. I'd like these returned values to populate a new column on a different sheet within the same workbook. I've found solutions for this type of multiple lookup using the INDEX and SMALL functions, but in all the examples, the lookup column (my column F) and the returned values column (my column R) are right next to each other, i.e. columns A and B. I'm unfamiliar with the functions used in these formulas, so I'm not getting working results when I try to manipulate the formula for the columns I'd like to use.

    Is it possible to do this when the 2 columns are not adjacent? I've attached a workbook as an example. Sheet 1 has the lookup column (Continuation) and the values that I want to be returned (ID #), and Sheet 2 has the values I'm looking for (depart, trans, vaca, TempAbs, ?) and a highlighted column where I'd like the ID #s to go.

    Thank you for your help!

    multiple lookup test.xlsx

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

    Re: Multiple lookup with non-adjacent columns

    This array formula** entered in A2:

    =IFERROR(INDEX(Sheet1!R:R,SMALL(IF(ISNUMBER(MATCH(Sheet1!F$2:F$22,A$1:E$1,0)),ROW(Sheet1!F$2:F$22)),ROWS(A$2:A2))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy down until you get blanks.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    09-15-2015
    Location
    Lodz, Poland
    MS-Off Ver
    2010
    Posts
    16

    Re: Multiple lookup with non-adjacent columns

    I propose:

    =IFERROR(INDEX(Sheet1!$R:$R, SMALL(IF($A$1=Sheet1!$F:$F, ROW(Sheet1!$F:$F)-ROW(Sheet1!$F$1)+1), ROW(1:1))),"" )

    It's also an array function(ctrl + shift + enter). You just need to change $A$1 reference for each column.

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

    Re: Multiple lookup with non-adjacent columns

    Quote Originally Posted by wator89 View Post
    =IFERROR(INDEX(Sheet1!$R:$R, SMALL(IF($A$1=Sheet1!$F:$F, ROW(Sheet1!$F:$F)-ROW(Sheet1!$F$1)+1), ROW(1:1) )),"" )
    You should avoid using entire columns as range references in array formulas. Use smaller specific ranges.

    Using the ROW function leaves the formula vulnerable to new row insertions. Insert a new row 1 and see what happens to the results. Use the ROWS function instead. It can account for new row insertions.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Multiple lookup with non-adjacent columns

    As an alternative here's a non-array (ordinary) formula that does the same thing.

    =IFERROR(INDEX(Sheet1!R:R,SMALL(INDEX((Sheet1!$F$2:$F$22<>Sheet2!$A$1:$E$1)*10^10+ROW(Sheet1!$F$2:$F$22),0),ROW(1:1))),"")
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Multiple lookup with non-adjacent columns

    ... or taking Tony's point:

    =IFERROR(INDEX(Sheet1!R:R,SMALL(INDEX((Sheet1!$F$2:$F$22<>Sheet2!$A$1:$E$1)*10^10+ROW(Sheet1!$F$2:$F$22),0),ROWS($1:1))),"")

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

    Re: Multiple lookup with non-adjacent columns

    Quote Originally Posted by Glenn Kennedy View Post
    As an alternative here's a non-array (ordinary) formula that does the same thing.
    The array formula is slightly faster to calculate.

    Also, ROW(1:1) leaves the formula vulnerable to new row insertions.

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Multiple lookup with non-adjacent columns

    Point 1, perhaps so, but non-array formulae are easier to keep working (accidental unsetting of the array). In general, most folk here seem to agree that non-array formulae are preferred, wherever possible.

    Point 2, agreed & see my comment at Post 6.

  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: Multiple lookup with non-adjacent columns

    Quote Originally Posted by Glenn Kennedy View Post
    In general, most folk here seem to agree that non-array formulae are preferred, wherever possible.
    I think that most folks would prefer the BEST solution to their task. Going to "extremes" to avoid an array formula is not a best solution IMHO.

    Not using array formulas is like a carpenter showing up on a job without a hammer!

    Sure, they have other tools that will get the job done but it's just not the same.

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Multiple lookup with non-adjacent columns

    Agreed with Tony. I think, as Experts/Gurus on a well-visited Excel Forum, we should be doing all we can to dispel this unfortunately widespread "fear" of array formulas.

    Even for new users, apart from the ever-so-mildly challenging problem of having to remember to (re)commit the formula with CSE, there is no other reason that I can think of which should mean that we promote non-array formulas over the equivalent array version, even more so since such practices often result in constructions which are not only more difficult to understand (try explaining the use of INDEX with zero parameter(s) as a substitute for CSE to a new user!) but also less efficient.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  11. #11
    Registered User
    Join Date
    09-15-2015
    Location
    Lodz, Poland
    MS-Off Ver
    2010
    Posts
    16

    Re: Multiple lookup with non-adjacent columns

    Quote Originally Posted by Tony Valko View Post
    You should avoid using entire columns as range references in array formulas. Use smaller specific ranges.

    Using the ROW function leaves the formula vulnerable to new row insertions. Insert a new row 1 and see what happens to the results. Use the ROWS function instead. It can account for new row insertions.
    Thanks for the tips, I have selected entire column in case there is more data. Maybe it would be a good idea to use dynamic ranges?

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Multiple lookup with non-adjacent columns

    It would be much better to use a named range!!

  13. #13
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Multiple lookup with non-adjacent columns

    It's almost always better to use dynamic ranges.

    Failing that, choosing a suitably large upper bound on the end row reference is still far, far preferable to using entire column references when the formula in question is an array formula. For example, if you only actually have data extending to row 1000, just one iteration of an array formula using entire column references would force Excel to calculate more than a million additional, unnecessary cells.

    Regards

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

    Re: Multiple lookup with non-adjacent columns

    Quote Originally Posted by wator89 View Post
    Maybe it would be a good idea to use dynamic ranges?
    Yes.

    We're all in agreement on that!

    Do you need assistance on how to do that?

+ 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. Replies: 4
    Last Post: 07-28-2015, 01:33 PM
  2. Look up a value from multiple columns and return an adjacent value
    By abaginska09 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-07-2013, 04:21 PM
  3. Need help with combining multiple non-adjacent columns
    By ngpm515 in forum Excel General
    Replies: 0
    Last Post: 11-17-2011, 04:18 PM
  4. Copy formulas to adjacent columns - multiple cells and multiple sheets
    By swanseaexcel in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-12-2011, 06:21 AM
  5. Looking through multiple columns, getting adjacent value
    By rockville9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2010, 04:11 PM
  6. Lookup adjacent column to multiple lookup columns.
    By JAMES4228 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-13-2009, 03:19 PM
  7. [SOLVED] Copying multiple columns not adjacent
    By Doug Wilson in forum Excel General
    Replies: 2
    Last Post: 07-08-2005, 04:05 PM

Tags for this Thread

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