+ Reply to Thread
Results 1 to 10 of 10

Return multiple matchng VLOOKUP values in one cell separated by commas?

  1. #1
    Registered User
    Join Date
    04-06-2013
    Location
    Buxte, Hude
    MS-Off Ver
    Office 2013
    Posts
    7

    Return multiple matchng VLOOKUP values in one cell separated by commas?

    Dear Excel Forum Community,

    I am using excel to do my invoicing.
    In one sheet I have all invoices ("invoices" sheet) and in another sheet I have the details of these invoices ("details" sheet). The invoices have numbers and the projects of which sometimes many make up one invoice have PO numbers.

    What I am trying to do is list the PO numbers included in an invoice (information from the details sheet) in a cell next to the invoice number (on the invoices sheet), separated by commas.

    So there is invoice PEPSI-JULY-2015. It contains the projects PO20058, PO24824, PO28992, PO298477, PO299338, and so on. (sometimes up to 25, 30 POs in one invoice)
    In the "details" sheet I have the invoice number in a column on the left, the items and price and other information including the PO-number in their respective columns next to the invoice number on the left.
    VLOOKUP will only look at the first match it finds and return it. I have found ways to look at the 2nd, 3rd and 4th match but I could not replicate it so far. But the real trick here seems to list all those matches in one cell (otherwise it would require way to much space and would clutter the whole invoice sheet of which the purpose is to get an overview, not to have to scroll around forever to see which PO-numbers are linked to an invoice number.

    Maybe there is another simpler solution of tweaking my tables than using VLOOKUP or INDEX MATCH to find all matches and list them in one cell - any help is appreciated.


    I will attach a generic version of my excel file. I have googled and run my brain until insanity and back to somehow make this work but only had weird or partial (only one PO) results. Mostly just errors.

    Thank you very much for looking at it. It seems like a common thing to want so I think it might help others as well. And I would absolutely prefer a function to a VBS as I would like to be able to understand how it works and I have no clue about macros and other things...


    (sheets other than the "invoices" and "details" sheet can be ignored - only the sheets "invoices" and "details" are required for this. There are some mistakes in the other sheets from deleting stuff.)

    Kind regards

    Patrick
    Attached Files Attached Files

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

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    Put this formula in P4 of the Details sheet:

    =IF(InvoiceDetails[[#This Row],[Invoice '#]]="","",InvoiceDetails[[#This Row],[Invoice '#]]&"_"&COUNTIF(C$4:C4,InvoiceDetails[[#This Row],[Invoice '#]]))

    and put the word Record in P3. The formula should automatically copy down, and it tags on a sequential number to the invoice number, thus creating a unique reference number for each record.

    Then in F4 of the Invoices sheet you can have this formula:

    =IFERROR(INDEX(InvoiceDetails[[#All],[PO]],MATCH(InvoicesMain[[#This Row],[Invoice '#]]&"_1",InvoiceDetails[[#All],[record]],0)),"")
    &IFERROR(", "&INDEX(InvoiceDetails[[#All],[PO]],MATCH(InvoicesMain[[#This Row],[Invoice '#]]&"_2",InvoiceDetails[[#All],[record]],0)),"")
    &IFERROR(", "&INDEX(InvoiceDetails[[#All],[PO]],MATCH(InvoicesMain[[#This Row],[Invoice '#]]&"_3",InvoiceDetails[[#All],[record]],0)),"")
    &IFERROR(", "&INDEX(InvoiceDetails[[#All],[PO]],MATCH(InvoicesMain[[#This Row],[Invoice '#]]&"_4",InvoiceDetails[[#All],[record]],0)),"")

    (I've manually put line-breaks in there to make it easier to follow). Again, this should copy down automatically, and will give you up to 4 PO numbers that are associated with the Invoice number. If you need more, then in edit mode on the cell you should <copy> the bottom part of the formula (shown in blue) and paste it to the end and change the sequence number (shown in red) as appropriate.

    Hope this helps.

    Pete

  3. #3
    Valued Forum Contributor
    Join Date
    12-28-2014
    Location
    NSW, Australia
    MS-Off Ver
    MS365
    Posts
    604

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    Hi guys, since no-one had answered this beforehand, I decided I'd have a go.
    I kind of had success, but when I came back here I saw that Pete beat me
    And since I know nothing about pivot tables, his formula kicks but on my clumsy attempt.
    I thought I'd place it here anyway so that maybe someone could tell me why it doesn't quite work.

    Well for a start, it is limited to 30 PO's and only 50 different invoice numbers, but that aside it totally misses PO 23513 no matter which invoice it is assigned to.

    Does it have something to do with me trying to use a pivot table as an array?

    Thanks for any input.
    Attached Files Attached Files

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

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    @Beamernsw

    In E4 of your new sheet, you have the term COLUMN(B:B), which returns the second matching record. However, that term is COLUMN(D:D) in F4, rather than COLUMN(C:C), so it will return the 4th matching record and miss the third - perhaps you deleted a column. Just copy the formula from E4 across, then copy those formulae down.

    Hope this helps.

    Pete

  5. #5
    Valued Forum Contributor
    Join Date
    12-28-2014
    Location
    NSW, Australia
    MS-Off Ver
    MS365
    Posts
    604

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    OMG, what a noob mistake.... Thanks, I looked and looked. No way could I see that

    Thanks Pete.

  6. #6
    Registered User
    Join Date
    04-06-2013
    Location
    Buxte, Hude
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    WANTED TO WRITE: (and its still valid, but please also read on to the next post)

    WOW!

    Thank you. I tried around for a while to make it work in my real version of the excel file and all that made me understand quite well how it works.

    You are inspiring and I will now start to inscribe in forums where I know stuff (languages, social justice, ...) to also give free advice!
    Last edited by zendoo; 12-10-2015 at 09:42 PM.

  7. #7
    Registered User
    Join Date
    04-06-2013
    Location
    Buxte, Hude
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    OOOPS, nope, actually it didn't work out that well. I insert a new row on top of the invoice details list in order to keep the newest ones on top, not on bottom. That destroys the numbering every time I do that. Is there a way to auto-update the numbering when a new line is inserted on top? (What happens is that the new entry will get a [invoicename]_1 and the older entry will also stay at [invoicename]_1, the name it was assigned earlier. So only the newer PO shows up in the POs field in the InvoicesMain table. I have thought about it a while but I do not know excel enough to even think of something that could fix this... Any ideas?
    (finding tips to use named ranges on google but have no clue how to yet... maybe I will find it, but so far no luck)
    (or OFFSET? or maybe use the COUNTIF to count down from 1000 [just to make sure :D])

    I also tried counting down (see three lines below here) but it amounts to the same problem - the lower values do not update and there will be double entries.

    I also changed the formula in details to
    =[@[Invoice '#]]&"_"&COUNTIF(C$4:C4,[@[Invoice '#]])
    =[@[Invoice '#]]&"_"&1000-COUNTIF(C$4:C4,[@[Invoice '#]])
    it works just as well but with the same problem of creating duplicates. Why do the IF-formula at all?



    I have tried leaving a blank line on top - this does the trick and makes the whole process count upwards and gives the new line a higher number - no clue as to why that happens, but it still doesn't recalculate the lower entries, i.e. I have [invoicename]_1, [invoicename]_2 already in the list, adding a new line on top with one empty line above makes another [invoicename]_2...


    And also having to leave a blank line on top doesn't seem like a very elegant solution...

    So I give up for now. Hoping for an answer here again !


    Thank you in advance. I am already giving advice on how to fix broken phone screens by the way...
    Last edited by zendoo; 12-10-2015 at 10:23 PM.

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

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    You usually add new data at the bottom of a file, and formulae are usually designed to be copied down a sheet. Post another example showing the problems that you have now, and I'll take a look at it tomorrow (it's 2AM here now).

    Pete

  9. #9
    Registered User
    Join Date
    04-06-2013
    Location
    Buxte, Hude
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    Thanks Pete. In the real version of this file there are 290 or so entries so adding lines to the bottom would be very impractical as I have to scroll down every time. It is a possibility but would be nicer to be able to keep my habit of adding to the top .

    It is 3:22 AM here now, I seem to not really get to this either ...

    Thanks a lot - whenever you find the time to look at it.

    I added a few lines to the top. As you can see the numbering doesn't update and there are duplicate invoice entries in the created column "Record" and those do not show in the POs field in the invoice sheet.


    Pat
    Attached Files Attached Files

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

    Re: Return multiple matchng VLOOKUP values in one cell separated by commas?

    Okay, change the formula in P4 to this and copy it down:

    =IF(InvoiceDetails[[#This Row],[Invoice '#]]="","",InvoiceDetails[[#This Row],[Invoice '#]]&"_"&COUNTIF(C$3:C4,InvoiceDetails[[#This Row],[Invoice '#]]))

    to allow you to insert your invoices at the top of the table. When you have inserted a new row 4, you must copy the formula from P5 into P4, and then the numbering will carry on automatically. Note that the only change is in the middle of the formula - C$4 has become C$3, as shown in red.

    If that now takes care of your original question, please select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Also, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ 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] Formula to count values in single cell separated by commas
    By aimeecrystalaid in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-25-2017, 01:01 AM
  2. [SOLVED] vLookup multiple values separated by ";" in single cell / return result in single cell
    By Tunesmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2015, 12:02 PM
  3. Replies: 8
    Last Post: 03-31-2015, 01:06 PM
  4. Returning Multiple Values Separated by Commas to a single cell
    By enragedpigeon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2015, 05:48 PM
  5. Replies: 3
    Last Post: 05-30-2012, 04:28 PM
  6. Find a Value In A Table of Cell Each With More Than 2 Values Separated By Commas
    By Misha322 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2012, 02:42 PM
  7. Replies: 7
    Last Post: 03-05-2010, 04:25 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