Function/Formula to return more than one result to a single cell

Reneek

New Member
Joined
Jun 21, 2011
Messages
24
I have a spreadsheet which calculates a grid reference

Based on the resultant grid reference i then want the name of that task to be identified in the grid

Using the formaula below - i have managed to get this to happen, however some grid references will have more than one task to go to it

I have managed to get it to return multiple task names with spaces but cannot get it to move to the next record?

=IFERROR(INDEX($O$2:$O$11,MATCH(C3,$N$2:$N$11,0)),0)&" "&IFERROR(INDEX($O$2:$O$11,MATCH(C3,$N$2:$N$11,0)),0)&" "&IFERROR(INDEX($O$2:$O$11,MATCH(C3,$N$2:$N$11,0)),0)

So in the grid where i want the results i get the same task repeated, as below (in a single cell)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Risk1<o:p></o:p>
Risk1<o:p></o:p>
Risk1


But it should read (in a single cell)
Risk 1
Risk 2
Risk 8


The grid reference is calculated to N2:N10 and the task name is shown in O2:010 (it is this task name/s which i want to return into the grid)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
For having the results in a single cell, you could add
the following function code in VBA to your workbook as a module.

In order to add the function to your workbook, run...

ALt+F11
Insert | Module
File | Close and Return to Microsoft Excel.
_________________________________________________________

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
________________________________________________________

Now equipped with ACONCAT...

Control+shift+enter, not just enter:

=SUBSTITUTE(aconcat(IF($N$2:$N$11=C3,", "&$O$2:$O$11,"")),", ","",1) <!-- / message --><!-- sig -->
__________________
Microsoft MVP - Excel
 
Upvote 0
That is awesome - thank you so much.

The data returned is

Risk1,
Risk2,
Risk8

Is there any way i can remove the comma after the first two?
 
Upvote 0
That is awesome - thank you so much.

The data returned is

Risk1,
Risk2,
Risk8

Is there any way i can remove the comma after the first two?
Try this...

Still array entered**:

=SUBSTITUTE(aconcat(IF($N$2:$N$11=C3," "&$O$2:$O$11,""))," ","",1)

** 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
That is awesome - thank you so much.

You are welcome.

The data returned is

Risk1,
Risk2,
Risk8

Is there any way i can remove the comma after the first two?

Yes, you can. The formula uses a comma followed by a space as separator. This can be reduced to just space or even replaced by alt+enter...

=SUBSTITUTE(ACONCAT(IF($N$2:$N$11=C3," "&$O$2:$O$11,""))," ","",1)

If you'd opt for alt+enter...

=SUBSTITUTE(ACONCAT(IF($N$2:$N$11=C3,CHAR(10)&$O$2:$O$11,"")),CHAR(10),"",1)

Recall that you need to confirm such formulas with control+shift+enter.

You would need to activate Wrap text for the formula cells if you opt for for the latter.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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