+ Reply to Thread
Results 1 to 27 of 27

VLookUp To Return Multiple Values

  1. #1
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    VLookUp To Return Multiple Values

    I need to do a VLookUp and return multiple results into 1 cell. For example, I have the following information. (assume the number are stock codes or something)

    Red 1234
    Red 2345
    Red 4321
    Red 5432
    Blue 7589
    Blue 8598
    Blue 7858
    Green 4659
    Green 9587
    Green 6859

    The above would be on one sheet, then on another sheet, in Column A, I'd have Red, Blue & Green in their own cells. Then in Column B, I would do a VLookUp using the adjacent cell as it's "target" and would want to result all possible results, not just the first

    IE, Cell A1 would say Red, and I'd want cell B1 to return "1234, 2345, 4321, 5432" as its value

    Is this possible?

    TIA,

    Mat

  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
    48,167

    Re: VLookUp To Return Multiple Values

    That's not how VLOOKUP works. AFAIK, you'd need a VBA User Defined Function (UDF).


    Regards, TMS
    Last edited by TMS; 01-22-2014 at 06:52 AM. Reason: grammar
    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
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    I know how a VLookUp works (I don't mean that condescendingly BTW), usually a VLookUp only return the first value. Or at least a modification of it that I have used in the past. I need something to return multiple cells into one cell....

  4. #4
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Kuwait
    MS-Off Ver
    Excel 2013
    Posts
    115

    Re: VLookUp To Return Multiple Values

    May be pivot is the answer.

    Chk the attached file.Pivot Solution.xlsx

  5. #5
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Thanks,

    I'll look into that. My "problem" is that (on this project) I have 238 rows of data - all with unique references (ie, red, blue, green) and I have another sheet to filter through containing 44,238 rows of data! I'd like to have it as automated as possible :D

  6. #6
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Kuwait
    MS-Off Ver
    Excel 2013
    Posts
    115

    Re: VLookUp To Return Multiple Values

    MAy be if you put ur actual sheet without confidential data, then probably we can assist u.

    Rgds
    AT

  7. #7
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    will do. I'll post it in a mo

  8. #8
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Ok,

    I've attached some sample data.

    Sheet 1 contains approximately 1,000 rows of data.

    Sheet 2 contains a handful of part numbers, of which I need to return all "Part Codes" that apply to that number. This needs to be returned on 1 single cell.

    Thank you
    Attached Files Attached Files

  9. #9
    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
    48,167

    Re: VLookUp To Return Multiple Values

    I know how a VLookUp works (I don't mean that condescendingly BTW), usually a VLookUp only return the first value.
    I never, for one moment, interpreted that as condescending

    VLOOKUP doesn't just usually return the first matching value, it always returns the first matching value, and only the first matching value. Shame really, because a lot of people, just like you, would like it to return all the matching values.

    The Pivot Table option maybe sufficient for your needs.

    I have updated the example provided by brandedadnan with some alternative views.

    Regards, TMS
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Quote Originally Posted by TMShucks View Post
    I never, for one moment, interpreted that as condescending

    VLOOKUP doesn't just usually return the first matching value, it always returns the first matching value, and only the first matching value. Shame really, because a lot of people, just like you, would like it to return all the matching values.

    The Pivot Table option maybe sufficient for your needs.

    I have updated the example provided by brandedadnan with some alternative views.

    Regards, TMS
    Thanks for this example.

    The data I'm currently working on is a very small amount. 238 product numbers is just clearance stock. I usually deal with data containing anywhere from 2,000 to 15,000 rows of unique Product Numbers, and have to look through a file containing anywhere around 20,000 rows of data to get Product Codes. The pivot table idea looks nice and simple, but really not suitable or efficient unfortunately

    Maybe I'm asking too much.

  11. #11
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Kuwait
    MS-Off Ver
    Excel 2013
    Posts
    115

    Re: VLookUp To Return Multiple Values

    I think in that case, u need vba.., cause vlook up will not work here...

  12. #12
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    hhhmmm........... is this something this Forum can provide support with?

  13. #13
    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
    48,167

    Re: VLookUp To Return Multiple Values

    This thread does something very similar:

    http://www.excelforum.com/excel-prog...-for-loop.html


    Regards, TMS

  14. #14
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Thanks

    It looks like it's time to speak to my Director and get Access or VBA and a training course booked. We're growing rapidly, and just taken some stuff in-house that we used to contract out.

    We would normally provide the data in separate rows (ie, as shown in my first example above with Red in 4 rows). I think that our 3rd party company must have consolidated all info into one cell as that is how it's required for upload purposes.

    Anyway......

  15. #15
    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
    48,167

    Re: VLookUp To Return Multiple Values

    Here is the code from that thread, slightly modified, and applied to your data.

    Please Login or Register  to view this content.

    Regards, TMS
    Attached Files Attached Files

  16. #16
    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
    48,167

    Re: VLookUp To Return Multiple Values

    It looks like it's time to speak to my Director and get Access or VBA and a training course booked.
    If you do not already own and use Access, I suspect that it will be relatively expensive to buy, especially if a lot of people will need to use the database you produce. In my experience, Access has quite a steep learning curve, particularly when you start designing forms and adding VBA code and queries.

    You could always recruit an Excel/VBA consultant in the short term to get it moving.

    Regards, TMS

  17. #17
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: VLookUp To Return Multiple Values

    Hi TMS -

    This would give an error due to large strings I believe.
    this one should work I think
    Please Login or Register  to view this content.
    event

  18. #18
    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
    48,167

    Re: VLookUp To Return Multiple Values

    @event21: thank you. It does indeed generate an error. I've tried (and, again, slightly modified your code) and it works perfectly. Interestingly, or not so, you can't resize the column to fit the collated data ... obviously, again, due to the size of the text string.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  19. #19
    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
    48,167

    Re: VLookUp To Return Multiple Values

    @event21: Edit ... never mind. I was asking for clarification but, as I look at it, I understand. The difference is that, for this version, you're separating the codes with commas whereas, in the earlier version, it was spaces. Thanks again.

    This, I understand:

    Please Login or Register  to view this content.

    But please can you talk me through the logic of this:

    Please Login or Register  to view this content.

    Thanks, TMS
    Last edited by TMS; 01-22-2014 at 09:06 AM.

  20. #20
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Thank you very much.

  21. #21
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Quote Originally Posted by TMShucks View Post
    @event21: thank you. It does indeed generate an error. I've tried (and, again, slightly modified your code) and it works perfectly. Interestingly, or not so, you can't resize the column to fit the collated data ... obviously, again, due to the size of the text string.

    Please Login or Register  to view this content.
    You Sir, are a star

    Thank you to all that have helped.

  22. #22
    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
    48,167

    Re: VLookUp To Return Multiple Values

    You're welcome. Thanks for the rep.


    All the credit goes to event21 ... the code is his, I just tweaked it about a bit and put it in the sample workbooks.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  23. #23
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Sorry to bump such an old thread.

    I thought I had this working, but still getting no success. When I run a Macro, it comes up with an error. When I open the debug window, this is the line that is highlighted

    Please Login or Register  to view this content.
    I really really do need to get this working now. I had a file the other week with over 600,000 rows of data. I split it up into sections of around 20,000 and did some copying and pasting until I had condensed down. The result - what I believe to be RSI. My fingers are killing from keyboard shortcuts etc.

    If it helps, I can start a new thread, and start "afresh" with some more sample data and how exactly I work with it at the moment.

  24. #24
    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
    48,167

    Re: VLookUp To Return Multiple Values

    If it helps, I can start a new thread, and start "afresh" with some more sample data and how exactly I work with it at the moment.
    Probably your best bet. This thread is nearly 12 months old. I think you need fresh eyes and new input.

    Regards, TMS

  25. #25
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Thanks. Having gone through some of my workload, 1 catalogue alone has 840,000 rows of data. I've estimated I can tidy up 30,000 rows a day without any other distractions, so that would take 28 days to just tidy up. I then need to do other things before making it live etc...

    New thread coming.

  26. #26
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: VLookUp To Return Multiple Values

    You originally asked for a formula solution, so I've taken your attachment from Post#8 and put this formula in C2 of Sheet1:

    =IF(A2="","-",A2&"_"&COUNTIF(A$2:A2,A2))

    Copy this down to the bottom of your data (or beyond - the hyphens indicate where the formula is active)

    Then in Sheet2 you can have this formula in B2:

    =IFERROR(INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&"_"&COLUMNS($B:B),Sheet1!$C:$C,0)),"")

    This will give you the Part code in one cell - copy the formula across to get the multiple part codes in adjacent cells. Copy the formula down for the other part numbers.

    Hope this helps.

    Pete

  27. #27
    Registered User
    Join Date
    06-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: VLookUp To Return Multiple Values

    Hhhmmmm.......... That certainly is one way of doing it, and definitely much better than my way.

    At the moment, I have to copy the data from a column, and paste as transpose (into rows), then delete the data from the cells I've just copied from. Once I have transposed all of this, I then do a string at the end to get all the data into one cell (which is ultimately how I have to have it in the end result).

    Basically, I do this

    Red 1234
    Red 2345
    Red 3456
    Blue 9876
    Blue 8765
    Blue 7654
    Blue 6543
    Yellow 2468
    Yellow 3579
    Yellow 4680




    I then Paste the values, and have the table beginning to look like this.

    Red 1234 2345 3456
    Red
    Red
    Blue 9876 8765 7654 6543
    Blue
    Blue
    Blue
    Yellow 2468 3579 4680
    Yellow
    Yellow

    I then use the filter, sort by column B, and delete all rows with a blank value in column B.

    Once I've added my string of =B2&", "&C2&", "&D2 etc I then get what I want which is

    Red 1234, 2345, 3456
    Blue 9876, 8765, 7654, 6543
    Yellow 2468, 3579, 4680

    It certainly looks like your method will work without requiring a lot of coding. I shall give it a try now
    Last edited by RandomlySet; 01-12-2015 at 09:26 AM.

+ 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. [SOLVED] VLOOKUP to return multiple corresponding values
    By Jackie5467 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 11-17-2013, 09:29 PM
  2. Vlookup function to return multiple values from multiple sheets
    By bsamant in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-13-2013, 11:31 AM
  3. Return Multiple Values Using VLookUp
    By akim1010 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-16-2013, 03:36 AM
  4. can a vlookup return multiple values and how
    By bajdr47 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-01-2010, 08:04 AM
  5. Use a VLookup to return multiple values
    By Kennethc in forum Excel General
    Replies: 3
    Last Post: 04-07-2009, 04:49 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