LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove
 
Posts: n/a
Default VLookUp function to return multiple rows

Toppers wrote...
I don't think you can do it without code...

....

Well not if there could be more than a few dozen items to concatenate,
but if there were fewer items, no code required.

"sebastian stephenson" wrote:
I have set of data

Key Text
1 x
1 y
1 z
2 a
2 b
3 c
3 d


Would this always be sorted by Key? I'll assume so, and I'll also
assume the table above, excluding the top row of labels, is named Tbl.

I want to use a function that will return

Key Text
1 x,y,z
2 a,b
3 c,d

....

If the result range were in D1:E4 with labels in D1:E1, try these
formulas.

D2:
=INDEX(Tbl,1,1)

E2:
=INDEX(Tbl,1,2)&IF(COUNTIF(INDEX(Tbl,0,1),D2)1,", "&INDEX(Tbl,2,2),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D2)2,","&INDEX(Tbl,3,2 ),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D2)3,","&INDEX(Tbl,4,2 ),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D2)4,","&INDEX(Tbl,5,2 ),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D2)5,","&INDEX(Tbl,6,2 ),"")

D3:
=INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$2:D 2))+1,1)

E3:
=INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$2:D 2))+1,2)
&IF(COUNTIF(INDEX(Tbl,0,1),D3)1,
","&INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$ 2:D2))+2,2),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D3)2,
","&INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$ 2:D2))+3,2),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D3)3,
","&INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$ 2:D2))+4,2),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D3)4,
","&INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$ 2:D2))+5,2),"")
&IF(COUNTIF(INDEX(Tbl,0,1),D3)5,
","&INDEX(Tbl,SUMPRODUCT(COUNTIF(INDEX(Tbl,0,1),D$ 2:D2))+6,2),"")

Fill D3:E3 down as far as needed.

On the other hand, if one uses Laurent Longre's MOREFUNC.XLL add-in,
the column E formulas could be reduced to

E2 [array formula]:
=MID(MCONCAT(IF(INDEX(Tbl,0,1)=D2,","&INDEX(Tbl,0, 2),"")),2,255)

Fill E2 down as far as needed.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get multiple matches when using the Vlookup function? Lisa F Excel Worksheet Functions 1 February 27th 06 11:17 PM
Can I return multiple columns from a vlookup? carolyn Excel Worksheet Functions 3 February 8th 06 09:46 PM
VLOOKUP - Multiple cells in lookup value RMF Excel Worksheet Functions 1 January 23rd 06 10:28 AM
Row Sequencing Mark Excel Worksheet Functions 8 August 18th 05 06:33 PM
VLOOKUP Function using multiple worksheets Fiona Excel Discussion (Misc queries) 0 March 10th 05 05:24 AM


All times are GMT +1. The time now is 12:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"