+ Reply to Thread
Results 1 to 13 of 13

How to perform lookup when lookup value not in first column of array?

  1. #1
    Registered User
    Join Date
    06-02-2009
    Location
    NJ, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    How to perform lookup when lookup value not in first column of array?

    I have 2 worksheets. The first is a single column of values. The second is a data array with multiple rows and columns.

    I need to perform a lookup/search of the values in worksheet 1 against the data array in worksheet 2. The returned value needs to be the cell adjacent to the right of the matched cell. I cannot simply use vlookup since the lookup values are not necessarily in the first column.

    I've been messing around with the index, match, countif functions but can't get it right. Can anyone help? I've included a simplified example below. The real data I'm working with actually has 3000+ columns of data, the data points repeat every 20 columns so there are 150 "sets" of data spreading horizontally across the spreadsheet.


    Worksheet 1 (lookup values):

    Color Returned Value
    Green 4
    Orange 7



    Worksheet 2 (data array):

    Color Number Color Number
    Blue 1 Black 2
    Red 3 Green 4
    White 5 Yellow 6
    Orange 7 Brown 8
    Silver 9 Pink 10

    So the formula I'm looking to create will be for the "Returned Value" column in the first table. In this example, Green is the lookup value, it is found in the data array (table 2) and returns the value located next to the cell (4). Same logic applies to the orange example and the response of 7.

    Hope this makes sense. Any help is appreciated.
    Last edited by neo95gt; 08-10-2014 at 08:59 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to perform lookup when lookup value not in first column of array?

    You have two choices. Simple first choice, make it one list of colours and values. Second messier choice, treat it as two sets of colour and value pairs. Lookup the value in the first list and use IFERROR to make it look at the second list if it's not in the first list.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: How to perform lookup when lookup value not in first column of array?

    Try this formula in B2 and copy down

    =SUMIFS($B$6:$D$10,$A$6:$C$10,A2)

    if you using Excel 2003 use this array formula

    =SUM(IF($A$6:$C$10=A2,$B$6:$D$10))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    A
    B
    C
    D
    1
    Color Returned Value
    2
    Green
    4
    3
    Orange
    7
    4
    Pink
    10
    5
    6
    Blue
    1
    Black
    2
    7
    Red
    3
    Green
    4
    8
    White
    5
    Yellow
    6
    9
    Orange
    7
    Brown
    8
    10
    Silver
    9
    Pink
    10
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Registered User
    Join Date
    06-02-2009
    Location
    NJ, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to perform lookup when lookup value not in first column of array?

    Quote Originally Posted by TMS View Post
    You have two choices. Simple first choice, make it one list of colours and values. Second messier choice, treat it as two sets of colour and value pairs. Lookup the value in the first list and use IFERROR to make it look at the second list if it's not in the first list.

    Regards, TMS
    The actual data I'm working with is much larger so both of your suggestions would not work. I'm working with 3,000+ columns and 400+ rows. So the solution needs to be able to handle scale. That's why I need a formula that will search the entire worksheet and return the data point I need.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to perform lookup when lookup value not in first column of array?

    I think you could extend the ranges in AlKey's solution. It just needs to refer to alternating columns. Have you tried that.

    It helps if you tell us what you're really trying to do instead of an over simplified example.

  6. #6
    Registered User
    Join Date
    06-02-2009
    Location
    NJ, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to perform lookup when lookup value not in first column of array?

    Quote Originally Posted by TMS View Post
    I think you could extend the ranges in AlKey's solution. It just needs to refer to alternating columns. Have you tried that.

    It helps if you tell us what you're really trying to do instead of an over simplified example.
    The actual data I'm working with contains a table array 3,000 columns long. The data points repeat every 20 columns. I also will need the return a value that is next to it as well as 4,5,6,7 columns next to it, so I need the flexibility to return any value I want basically.

  7. #7
    Registered User
    Join Date
    06-02-2009
    Location
    NJ, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to perform lookup when lookup value not in first column of array?

    This is the solution I came up with, but couldnt figure how to return a cell +1 columns to the matched value

    =Index(A1,Countif(A1:XFD400,A1))

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: How to perform lookup when lookup value not in first column of array?

    This will work for you (based on Trvor's suggestion), you just have to adjust the ranges...
    =IFERROR(VLOOKUP(A2,$A$10:$B$14,2,0),VLOOKUP(A2,$C$10:$D$14,2,0))

    If you have a 3rd "set" of data, just add another IFERROR()
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  9. #9
    Registered User
    Join Date
    06-02-2009
    Location
    NJ, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to perform lookup when lookup value not in first column of array?

    Quote Originally Posted by FDibbins View Post
    This will work for you (based on Trvor's suggestion), you just have to adjust the ranges...
    =IFERROR(VLOOKUP(A2,$A$10:$B$14,2,0),VLOOKUP(A2,$C$10:$D$14,2,0))

    If you have a 3rd "set" of data, just add another IFERROR()
    yea the problem is I do have a 3rd "set" of data. I actually have like 200 sets of data, so that's why I can't just build a forumla like that. The formula needs the ability to read the entire table at once, and return a result X amount of cells away. I really wish there was a vlookup that didnt hinge on the first column in the array, but instead searched the entire table array.

  10. #10
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: How to perform lookup when lookup value not in first column of array?

    I edited, my response and for some reason, rather than adjusting the post it posted my new version as well as the old version. not sure how to delete the old version so here is an explanation (hopefully replacing the old version).
    Last edited by SomeDude0nline; 08-12-2014 at 10:16 AM.

  11. #11
    Registered User
    Join Date
    07-17-2014
    Location
    Chico, CA
    MS-Off Ver
    MS Office 2010
    Posts
    20

    Re: How to perform lookup when lookup value not in first column of array?

    I don't know how to work with Macros but I would suggest bringing in someone that's very familiar with Macros. I think the solution is probably to set up a ton of index match formulas. Basically you set up each formula to return the next column of matching data but as you have several hundred columns this would be too time consuming as you said. However, what I do know about macros is that they make repetitive tasks very simple. There is probably a way to set up a Macro to create all of the formulas for you. Then it would just require some simple data manipulation.

    Also, have you considered lining up each pair of columns into one pair of columns? You probably have thousands of rows so this may not be a great solution but if you copy all of your data to a new spreadsheet and take columns C&D and add them to the bottom of columns A&B and so on then you could simply use one index match formula. And because you copied the information to a new spreadsheet you would still have the data in the original format on the on spreadsheet.

    I think I understand what you're trying to do but if not then I'm sorry for my poor suggestions. Good Luck.
    Last edited by SomeDude0nline; 08-12-2014 at 10:14 AM.

  12. #12
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to perform lookup when lookup value not in first column of array?

    This array formula (enter with Ctrl + Shift + Enter) might work for you:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by newdoverman; 08-12-2014 at 11:00 AM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  13. #13
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to perform lookup when lookup value not in first column of array?

    Here is an expanded and corrected solution. I added two columns to show that it would work with more data. The K for SMALL was also changed to 1 from the COLUMNS... which was incorrect.


    Array enter (Ctrl + Shift + Enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by newdoverman; 08-12-2014 at 02:54 PM.

+ 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: 7
    Last Post: 06-19-2011, 12:51 PM
  2. Replies: 13
    Last Post: 01-07-2011, 08:33 AM
  3. Perform a two column lookup that returns a value from another column?
    By okstate1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2010, 07:13 PM
  4. how do I perform a lookup on an 80,000 line array?
    By Bartimus in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-13-2006, 10:15 PM
  5. [SOLVED] How do you perform a two-column lookup?
    By Kymm in forum Excel General
    Replies: 5
    Last Post: 10-20-2005, 01:05 PM

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