conditional concatenate multiple values from row above

mholland

New Member
Joined
May 29, 2009
Messages
3
so, I have what I imagine to be a simple and [I'm thinking what must be a] frequent problem ... I have two rows, one on top of the other ... top row is types of fruit [one per cell], lower row is simply "Y" or "N" depending on whether is like the fruit or not.

what i want to do is, on a different tab in the same spreadsheet, in single cell, display all the fruits I like, separated by a comma [apples, pears, peaches].

I need to do this by formula, rather than by macro, just to make it more difficult ... I have tried hlookups, index/match, sumif, advanced filter, and I still can't get it. I think there is something in the concept of an array entered something like "if(lower_range='y', upper_range,)", but i can't get any further than the first fruit i like.

thanks in advance, any help appreciated, Matt
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Download and install the free add-in Morefunc.xll from:

http://xcell05.free.fr/morefunc/english/index.htm

Alternative download site:

http://www.download.com/Morefunc/3000-2077_4-10423159.html

This method is limited to a max of 255 characters that the formula will return!

Using the MCONCAT function from the add-in...

A1:E1 = fruit names
A2:E2 = Y or N

Array entered**

=SUBSTITUTE(TRIM(MCONCAT(IF(A2:E2="Y",A1:E1,"")&" "))," ",",")

** 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.
 
Upvote 0
The following method is not as elegant but does not require a download. There is a still limit on characters which varies with the data but is over 1000.

It requires a helper row, in the example below copy the formula in a4 across (it does not matter if it is copied beyond the end of the data).
Then reference cell A4 in your second sheet.

Excel Workbook
ABCDE
1ApplePearGrapeOrangeBanana
2YYNNY
3
4Apple,Pear,BananaPear,BananaBananaBananaBanana
Sheet1



Excel Workbook
A
1Apple,Pear,Banana
Sheet2
 
Upvote 0
love it, love it ... much thanks ... I'm going to go with a little variant on the helper row doo-dah, as I can't download [spready being run by hundreds of people on locked down pc's]

so in my final view, each column in the helper row will look for a 'Y', and add the fruit to the contents of the previous helper row cell ... repeat this formula right to left, then link to my final cell to present the fully concat'ed string.

you're both stars, well done indeed.
 
Upvote 0
You could also avoid any helper cells by concatenating several IFs, e.g.

=SUBSTITUTE(IF(A2="Y",", "&A1,"")&IF(B2="Y",", "&B1,"")&IF(C2="Y",", "&C1,"")&IF(D2="Y",", "&D1,"")&IF(E2="Y",", "&E1,""),", ","",1)
 
Upvote 0
I'm going to go with a little variant on the helper row doo-dah

Be careful if you try to simplify the formula I gave, the formula I gave ensures there is no comma at the end of the final string, including when the rightmost fruits contain a 'N'. If all you do is check for 'Y' you will get the end comma or zero's! :)
 
Upvote 0
Thanks AndyB ... I reread your formula, and realised you had already produced exactly what I thought I was going to do ... apologies.

I still think there is something possible using arrays, but this 'helper row-if then' solution will be more than adequate

thanks again all
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top